Forum Moderators: coopster

Message Too Old, No Replies

redirect user based upon from entry

redirect if field is blank

         

flying monkey

12:00 am on Nov 13, 2003 (gmt 0)

10+ Year Member



is there a way to rediect a user to the log in screen if he/she has left the user name field blank?

jatar_k

12:22 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if ($_POST['username'] == "") header("Location: login.php");

assuming the username was posted to your script froma form and the text field was named username, this would send them back to a script named login.php located in the same directory.

You could always just reinclude the login form on error as well.

[edited by: jatar_k at 12:51 am (utc) on Nov. 13, 2003]

Birdman

12:46 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Shouldn't it be:

if ($_POST['username'] == "") header("Location: login.php");

jatar_k

12:51 am on Nov 13, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



thanks Birdman I seem to have left that out

flying monkey

4:37 am on Nov 13, 2003 (gmt 0)

10+ Year Member



well thats what i have right now and it does not seem to work

PSWorx

4:43 am on Nov 13, 2003 (gmt 0)

10+ Year Member



As jatar said just include the form again if an error occurs, i.e. if the password isnt set:

if($field[user]!=$nuser or $field[pass]!=$npass or $field[email]!=$nemail)
{
echo"<h2 id=\"loginhead\">Please login to continue:</h2>\n";
echo"<h3 id=\"loginhead\">Wrong login details, please try again:</h3>\n";
echo login_form();
}

Thats a snippet of my login area for something, the vars are checked from a database (the user inputs on the form) so you would have to modify it to your needs.

Hope that helps to some extent.... just hope i get a reply to my post.

Birdman

1:01 pm on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you say it doesn't work, do you mean it does not redirect or that you are getting an error?

I suppose you could be using an older version of PHP, which would require using $HTTP_POST_VARS['username'] instead of $_POST['username'].

You're welcome jatar_k, I don't like second guesing the mod ;)

flying monkey

4:35 pm on Nov 15, 2003 (gmt 0)

10+ Year Member



no i am using the newest version of php. it just not redirect thats all

Timotheos

5:22 pm on Nov 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ya figure it out yet?

Seems to me you're going to have to break it down to locate the problem. You should simply put header("Location: login.php") to see if that works by itself. If it does then the problems with the $_POST['username'] variable. Echo it to see what you get.

Tim