Leuven Wang
Leuven Wang

Reputation: 151

Is there a way to redirect to another page in php without using header()?

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

Answers (3)

user3509666
user3509666

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

rjdown
rjdown

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

Related Questions