Jump to content

Recommended Posts

Hey guys,

Does anyone know how to redirect a user to a specific page based on a login?

Essentially, there are only 3 separate pages involved, ie bob, sue and mary's.

When they enter their username and password I want them to be redirected to the appropriate corresponding page. This is the code I have below, but I am getting a parse error on line 11 (which is just a curly bracket -if the syntax was wrong i would have thought the parse error would be earlier on in the script).

Any suggestions?

 

 

<?PHP

if (!isset($username['bob']) || !isset($password['bob']))

{

header( "Location: http://www.somesite.com/bob.html" );

}

elseif (!isset($username['sue']) || !isset($password['sue']))

{

header( "Location: http://www.somesite.com/sue.html" );

}

else (!isset($username['mary']) || !isset($password['mary']))

{

header( "Location: http://www.somesite.com/ciara.html" );

}

?>

Link to comment
https://forums.phpfreaks.com/topic/44033-simple-php-redirect/
Share on other sites

for else you must not set a condition. And also: Break executing the script by exit;

So:

<?php
if (!isset($username['bob']) || !isset($password['bob']))
{
header( "Location: http://www.somesite.com/bob.html" );
exit;
}
elseif (!isset($username['sue']) || !isset($password['sue']))
{
header( "Location: http://www.somesite.com/sue.html" );
exit;
}
else
{
header( "Location: http://www.somesite.com/ciara.html" );
exit;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/44033-simple-php-redirect/#findComment-213830
Share on other sites

Thanks Lumio, well that kinda works, insofar as a page is displayed but it is only the else statement that is calling the page. The first two don't get called when their username and password are entered, so it is always the same person's page loading.

Should it have to connect to the db to verify the username password combo? I personally don't see why, as I thought I was just telling it to pull one of three pages linked to one of three user/pswd combos.

 

Link to comment
https://forums.phpfreaks.com/topic/44033-simple-php-redirect/#findComment-214027
Share on other sites

if (!isset($username['bob']) || !isset($password['bob']))
{
header( "Location: http://www.somesite.com/bob.html" );
exit;
}[/php
You're telling if $username['bob'] is not set or $password['bob'] is not set, it should redirect to bob.html
Thats because of "!".
And it would be the best to make those requests by db.
For instance:
[code]SELECT `username` FROM `users` WHERE `username` = 'bob' AND `password` = 'bob' LIMIT 1;

If there is one row:

<?php
   $result = mysql_query("SELECT `username` FROM `users` WHERE `username` = 'bob' AND `password` = 'bob' LIMIT 1;");
   if (mysql_num_rows($result)) {
      header( "Location: http://www.somesite.com/bob.html" );
      exit;
   }
?>

Link to comment
https://forums.phpfreaks.com/topic/44033-simple-php-redirect/#findComment-214128
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.