CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Apache configuration (http://www.codingforums.com/forumdisplay.php?f=69)
-   -   mod rewrite help (http://www.codingforums.com/showthread.php?t=272303)

DjDanHayden 09-05-2012 02:16 PM

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 ? :thumbsup:

abduraooft 09-06-2012 09:46 AM

Quote:

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';
  }




All times are GMT +1. The time now is 01:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.