954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP problem - register page

Hey everyone. I just recently set up(or tried to) a userdatabase where people can log in and see a user edit page. For some reason when you try to register, instead of redirecting to the successfull register page, it just goes to a page, "process.php" which process the login when clicked. Below is my register function... can anyone see a problem?? Thanks.

function procRegister()
    {
        global $session, $form;

        //Registration attempt
        $retval = $session->register( $_POST['username'], $_POST['password'], $_POST['email'] );
        
        //Registration success
        if( $retval == 0 )
        {
            $_SESSION['reguname']   = $_POST['username'];
            $_SESSION['regsuccess'] = true;
            header( "Location: ".$session->referrer );
        }
        
        //Error found with form
        else if( $retval == 1 )
        {
            $_SESSION['value_array'] = $_POST;
            $_SESSION['error_array'] = $form->getErrorArray();
            header( "Location: ".$session->referrer );
        }
        //Registration attempt failed
        else if( $retval == 2 )
        {
            
            $_SESSION['reguname']  = $_POST['username'];
            $_SESSION['regsuccess'] = false;
            header( "Location: ".$session->referrer );
        }
    }
Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 

On log in success you redirect to $session->referrer, which unlikely is the success page. Change it to the url of your success page.

php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

I changed it to the following but even then it stays on process.php and I cant get past it. Any help would be much apprecaited.

header( "Location: ".$session->referrer );
Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 

If anyone can help, please, send me an email at [email]solidgold10287@aol.com[/email] or im me at solidgold10287 and you can see what I am experiencing. Thanks!

Barefootsanders
Junior Poster
166 posts since Oct 2006
Reputation Points: 10
Solved Threads: 3
 

Instead of header( "Location: ".$session->referrer ); put the success page in a different variable e.g.

$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$good = 'success_page.php';

header("Location: http://$host$uri/$good ");

And if you want to add maybe an error page in a different variable you could do the following:

$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$good = 'success_page.php';
$bad = 'denied.php';

header("Location: http://$host$uri/$bad ");

Just a thought

darren2005
Junior Poster in Training
58 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2
 

<?php
$con = mysql_connect('localhost', 'root', '') OR die("Error: ".mysql_error());
mysql_select_db('db_name', $con) OR die("Error: ".mysql_error());

function protect($string){
$string = mysql_real_escape_string($string);
$string = strip_tags($string);
$string = addslashes($string);

return $string;
}
if(!$_POST['submit']){
echo "\n";
echo "\n";
echo "Registration Form\n";
echo "Username\n";
echo "Password\n";
echo "Confirm\n";
echo "E-Mail\n";
echo "\n";
echo "\n";
}else {
$username = protect($_POST['username']);
$password = protect($_POST['password']);
$confirm = protect($_POST['passconf']);
$email = protect($_POST['email']);

$errors = array();

if(!$username){
$errors[] = "Username is not defined!";
}

if(!$password){
$errors[] = "Password is not defined!";
}

if($password){
if(!$confirm){
$errors[] = "Confirmation password is not defined!";
}
}

if(!$email){
$errors[] = "E-mail is not defined!";
}



if($username){
if(!ctype_alnum($username)){
$errors[] = "Username can only contain numbers and letters!";
}

$range = range(1,32);
if(!in_array(strlen($username),$range)){
$errors[] = "Username must be between 1 and 32 characters!";
}
}

if($password && $confirm){
if($password != $confirm){
$errors[] = "Passwords do not match!";
}
}

if($email){
$checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
if(!preg_match($checkemail, $email)){
$errors[] = "E-mail is not valid, must be [email]name@server.tld[/email]!";
}
}


if($username){
$sql = "SELECT * FROM `users` WHERE `username`='".$username."'";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) > 0){
$errors[] = "The username you supplied is already in use!";
}
}

if($email){
$sql2 = "SELECT * FROM `users` WHERE `email`='".$email."'";
$res2 = mysql_query($sql2) or die(mysql_error());

if(mysql_num_rows($res2) > 0){
$errors[] = "The e-mail address you supplied is already in use of another user!";
}

}

if(count($errors) > 0){
foreach($errors AS $error){
echo $error . "
\n";
}
}else {
$sql4 = "INSERT INTO `users`
(`username`,`password`,`email`)
VALUES ('".$username."','".$password."','".$email."')";
$res4 = mysql_query($sql4) or die(mysql_error());
echo "

You have successfully registered with the username ".$username." and the password ".$password."!";
}
}

kumar_kagathara
Newbie Poster
1 post since Aug 2009
Reputation Points: 9
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You