Reputation: 151
Is there a way to redirect to another page in php without using header()? I can't use header() because I am outputting some stuff first to the page. I've considered using Javascript's window.location but I'm using an if statement in php so is there any way in php to go to another page without using header()? Thanks in advance.
Upvotes: 0
Views: 2743
Reputation: 1
Have a look at cURL especially curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
Upvotes: 0
Reputation: 11375
I can't use header() because I am outputting some stuff first to the page.
You shouldn't dismiss using header()
. Using header()
is still achievable by using output buffering.
For example:
<?php
ob_start(); //start the buffer
echo "This is some output"; //Output data
ob_clean(); //Erase the buffer content
header('Location: http://google.com'); //Redirect user
Upvotes: 2
Reputation: 9227
Using PHP? No.
You already mentioned using JS and window.location.
The only other option is Meta refresh:
<meta http-equiv="refresh" content="0; url=http://example.com/">
Upvotes: 2