Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Nice Profile URL? Re: Nice Profile URL?

#95914
bungle
Member

Expanding on the code i gave you in the other thread at https://css-tricks.com/forums/discussion/15865/if-id-does-not-exists-php#Item_5

PHP can do the redirect for you with a header rewrite – but, and this is important, the header rewrite only works if you have not yet outputted anything else so this PHP code needs to come at the very top of your php file with no whitespace before it


$id  = mysql_real_escape_string($_GET);
$sql = "SELECT * FROM users WHERE id=$id";
$result = mysql_query($sql);

if (mysql_num_rows($result)==0) {
echo ('User never existed');
}
else if (mysql_num_rows($result)==1) {
$userinfo = mysql_fetch_array($result);
if (!$userinfo) {
echo ('User no longer exists.');
}
else {
$username = $userinfo;
header('Location: http://www.yoursite.com/'.$username);
}
}
?>