Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder DjDanHayden's Avatar
    Join Date
    Nov 2008
    Location
    Ireland
    Posts
    55
    Thanks
    18
    Thanked 0 Times in 0 Posts

    mod rewrite help

    Hi,

    I are trying to mod rewrite my profile.php?id=1 to profile/Username


    I have this code in my .htaccess


    PHP Code:
    RewriteEngine on
    RewriteBase 
    /
    RewriteRule ^profile/(.*)$ profile.php?id=$

    and this code in my php file profile.php

    PHP Code:
    $url_parts explode("/"$_GET['url']);
    $friendly_name $url_parts[0];
    $friendly_name mysql_real_escape_string($friendly_name);
    $name $friendly_name;

    if(
    $name != "" && $name != NULL)
    {
      
    $result mysql_query("SELECT userid FROM user WHERE username='".$name."'");
      if(
    mysql_num_rows($result) > 0)
      {
        
    $assoc mysql_fetch_assoc($result);
        
    $account $assoc['id'];
      }
      else
      {
        echo
    'Does not exist';
      }
    }
          
    $id == $account


    When i try to echo the users $id or even $name it will not echo ?

    Can anyone help ?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    I are trying to mod rewrite my profile.php?id=1 to profile/Username
    I think, you need something like
    Code:
    #htaccess
    RewriteRule ^profile/(.*)$ profile.php?name=$1
    PHP Code:
    #PHP
    $name=mysql_real_escape_string(trim($_GET['name']));
    if(
    $name != "" && $name != NULL)
    {
      
    $result mysql_query("SELECT userid FROM user WHERE username='".$name."'");
      if(
    mysql_num_rows($result) > 0)
      {
        
    $assoc mysql_fetch_assoc($result);
        
    $account $assoc['id'];
      }
      else
      {
        echo
    'Does not exist';
      }

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •