-6

I am working on login functionality.

So what I want to do is, on form submission from login.php if details are correct it should go to home.php else it should go back to login.php.

My login processing is on process.php. But I don't know how to redirect/dispatch to appropriate page from process.php.

Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44
Ankit
  • 6,554
  • 6
  • 49
  • 71
  • 3
    -1 for lack of effort. [_other questions_](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php), [_another_](http://stackoverflow.com/questions/4871942/how-to-redirect-to-another-page-using-php?rq=1), [_another_](http://stackoverflow.com/questions/15670910/redirecting-php?rq=1) how many you want? – itachi Jul 07 '13 at 18:01

3 Answers3

1

Use header function like this:

header('Location: login.php');
exit;

But don't print any html output before calling header function else it will result in an error.

Ankit
  • 6,554
  • 6
  • 49
  • 71
Shashwat Kumar
  • 5,159
  • 2
  • 30
  • 66
0

header('Location: http://someweb.com'); will redirect the user.

Evaldas Raisutis
  • 1,628
  • 4
  • 18
  • 32
  • 1
    The second part of your answer is unture. *"HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs."* - [PHP Documentation](http://us3.php.net/manual/en/function.header.php) – animuson Jul 07 '13 at 18:28
0

Try something like this :

<?php
session_start();
//do some login processing

if(login === true){
    exit(header('Location: home.php'));
}else{
    //Extra marks set a reason why failed
    $_SESSION['error'] = 'Some error about why it failed';
    exit(header('Location: login.php'));
}
?>

exit(header('Location: *')); is what your after.

Ankit
  • 6,554
  • 6
  • 49
  • 71
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106