Hi.
I use the following code to redirect someone back to the 'sign up' page if their desired username is taken.
As you can see, I want them to be redirected to the original sign up page ('index.php') to try again.
My problem is that when a new user tries to register, they may have been referred by a current user so may have clicked through the link e.g. .com/index.php?id=Chris (so 'Chris' has referred the new user).
I need the PHP code to make the page redirect back to index.php?id=Chris rather then just index.php?id=
Could anyone please please please help. I have tried my brains off to get get it to work but have had no luck.
If this helps, I use the following code on the 'index.php?id=Chris' page to catch the referer from the link and insert it into a hidden field on sign up...
Thanks.
I use the following code to redirect someone back to the 'sign up' page if their desired username is taken.
PHP:
//make query to database
$sql ="SELECT * FROM $table_name WHERE username= '$_POST[username]'";
$result = @mysql_query($sql,$connection) or die(mysql_error());
//get the number of rows in the result set
$num = mysql_num_rows($result);
//checks it see if that username already exists
if ($num != 0){
header('Location:../index.php?id=');
exit;
}
As you can see, I want them to be redirected to the original sign up page ('index.php') to try again.
My problem is that when a new user tries to register, they may have been referred by a current user so may have clicked through the link e.g. .com/index.php?id=Chris (so 'Chris' has referred the new user).
I need the PHP code to make the page redirect back to index.php?id=Chris rather then just index.php?id=
Could anyone please please please help. I have tried my brains off to get get it to work but have had no luck.
If this helps, I use the following code on the 'index.php?id=Chris' page to catch the referer from the link and insert it into a hidden field on sign up...
PHP:
$id = trim($_GET['id']);
if(preg_match("/([^a-z0-9]+)/i", $id))
{
die('Invalid ID');
}
echo '<input type="hidden" name="referredby" value="' . $id . '">';
Thanks.
Last edited:






