jameson9 Posted March 23, 2007 Share Posted March 23, 2007 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" ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44033-simple-php-redirect/ Share on other sites More sharing options...
Lumio Posted March 23, 2007 Share Posted March 23, 2007 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44033-simple-php-redirect/#findComment-213830 Share on other sites More sharing options...
jameson9 Posted March 24, 2007 Author Share Posted March 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/44033-simple-php-redirect/#findComment-214027 Share on other sites More sharing options...
Lumio Posted March 24, 2007 Share Posted March 24, 2007 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44033-simple-php-redirect/#findComment-214128 Share on other sites More sharing options...
jameson9 Posted March 25, 2007 Author Share Posted March 25, 2007 Hm, not sure I follow you Lumio. That would only be good for "bob"'s redirect, but not the other two. Also, these people will already be logged into the site, so do I need to include all the connect to db statements in my php script? Quote Link to comment https://forums.phpfreaks.com/topic/44033-simple-php-redirect/#findComment-214769 Share on other sites More sharing options...
Lumio Posted March 25, 2007 Share Posted March 25, 2007 just take that ! away Quote Link to comment https://forums.phpfreaks.com/topic/44033-simple-php-redirect/#findComment-214772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.