user57129
user57129

Reputation: 309

how to redirect in PHP without javascript or Headers

I was wondering if there is any way I can redirect my login page automatically to another page.php without using Javascript at all or headers, because I already try with the last ones, but I need to send some echo before that.

You see, is for a log-in process, after the log-in i wanna be capable of send different users to different page.php according to the type of user this will be, so that will be the propose of this.

I've already checked for this matter before but I can't find a single answer than doesn't suggest the use of headers, or JavaScript.

If you see some other question than actually answer this please link it but first be sure it actually doesn't use JavaScript or headers to do it.

Upvotes: 0

Views: 583

Answers (2)

Jay Bhatt
Jay Bhatt

Reputation: 5651

Although you have mentioned in the question that you don't want to use headers. Probably because you can't echo a message, But using the header below you can both echo a message and redirect a user to next page.

header( "refresh:5; url=wherever.php" ); //Redirect page after five seconds.
echo 'Redirecting in 5 seconds';

EDIT: Redirect users to different URLs.

$url = 'user_home.php';
if($user == 'admin'){
   $url = 'admin_home.php';
}

header( "refresh:5; url= $url" ); //Redirect page after five seconds.
echo 'Redirecting you to your home in 5 seconds. Please wait.';

Upvotes: 0

Krimson
Krimson

Reputation: 7674

echo '<meta http-equiv="refresh" content="0; url=http://example.com/" />'

Echo this in the <head></head> section of your page

Upvotes: 1

Related Questions