|
|
|
|
![]() ![]() |
Sep 13 2007, 09:47 AM
Post
#1
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 4 Joined: 6-September 07 Member No.: 24,641 |
Hey Guys..
I'm using PHP to develop a small login module. I need to forward the user to a new page if the user has entered a valid user name and password. I submit the form to the same page which has the login form, and does the validations there. I do not know how to forward the user to another page by checking a certain condition in php. Please be kind enough to help me out here. Thanks in advance, Nuwan. |
|
|
|
Sep 13 2007, 10:43 AM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 286 Joined: 17-June 07 Member No.: 22,702 |
I think you just output a JavaScript tag with instructions for the redirection if the condition is met.
If the condition isn't met, the script tag simply won't exist, and therefore the redirect won't happen. BTW, your topic belongs in the PHP forum. This post has been edited by dserban: Sep 13 2007, 10:43 AM |
|
|
|
Sep 13 2007, 11:48 AM
Post
#3
|
|
|
Absolute Newbie Group: Admin Posts: 884 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 |
What you need here is the header function.
Like so: CODE <? php if($_POST['username'] == 'Nuwan'){ header('Location: http://www.example.com/authorized.php'); } else{ header('Location: http://www.example.com/login.php'); } ?> Of course, you'll need a way to compare your username and password to a database or list of users but you didn't ask that question so I'll assume for now that you either don't need it yet or have already figured that out. Hope this helps. vujsa |
|
|
|
Sep 14 2007, 02:55 AM
Post
#4
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 4 Joined: 6-September 07 Member No.: 24,641 |
Hey Guys..
Thanks for all the help. I got it working now, by using header ('Location : url');. Ya i got the database stuff figured out. Thanks, Nuwan. |
|
|
|
Sep 14 2007, 08:32 AM
Post
#5
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 998 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
It is only a matter of time until you receive an error message saying "Headers already sent" - this will, of course, disallow you to redirect the user to another page. This is because you have already outputted some data to the page. If you ever encounter this problem, and you can't avoid it, you will have to use JavaScript.
CODE <script type="text/javascript"> window.location = "Redirection URL"; </script> As this can be used anywhere in the page, it is more convenient, but header() is always a better option |
|
|
|
Sep 14 2007, 04:36 PM
Post
#6
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 5 Joined: 14-June 07 From: Los Angeles Member No.: 22,639 |
Using javascript the redirect a page is the worst way ever! If you have to do something in the actual code php spits out why not just use meta tag to redirect?
|
|
|
|
Sep 14 2007, 05:46 PM
Post
#7
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 998 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
Because it would have to be located between the HEAD tags
|
|
|
|
Sep 17 2007, 08:48 PM
Post
#8
|
|
|
Advanced Member Group: Members Posts: 182 Joined: 15-November 05 From: Inland from the Left Coast of Canada Member No.: 9,627 |
It is only a matter of time until you receive an error message saying "Headers already sent" - this will, of course, disallow you to redirect the user to another page. This is because you have already outputted some data to the page. If you ever encounter this problem, and you can't avoid it, you will have to use JavaScript. CODE <script type="text/javascript"> window.location = "Redirection URL"; </script> As this can be used anywhere in the page, it is more convenient, but header() is always a better option Or learn how to use ob_start(), and the associated functions. QUOTE This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.
|
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 21st August 2008 - 11:24 PM |