Redirect page to previous PHP (history.back)

Asked

Viewed 270 times

-1

I’m going through a little problem, when I buy an item in the store it redirects to the main store page, but the store is by category, I wanted to put for when to buy stay on the same page or a history.back with a delay I don’t know if it’s possible. Please if anyone can help.

$redirectLoc = $insertItem? '/loja.php':'index.php';

This is Redirect where you’re going.

$redirectLoc = $insertItem? '/#':'index.php';
$redirectLoc = $insertItem? 'javascript:history.back()':'index.php';
$redirectLoc = $insertItem? '/loja.php?categoria=?':'index.php';

But I can’t in any way, can anyone help me please?

if($redirectLoc) {
    // Redirect to the specific page
    header("Location: $redirectLoc");
    exit();
}

?>

This is another similar code you have in . php I don’t know if this can help.

1 answer

1


javascript:history.back() does not work in the header, this is instruction of the response http header and not of the page body. To make it work it has to be something like:

if($redirectLoc) {
    echo '<script>history.back();</script>';
    exit;
}

If you want to come back more than one:

if($redirectLoc) {
    echo '<script>history.go(-2);</script>';
    exit;
}

HTTP works like this, the content is downloaded and then the browser will render and run the javascript scripts, this after downloaded, directly in your browser, IE, has no relation to what is in PHP, has already been downloaded, the browser doesn’t even know that it was generated via PHP on the server-side (server side)

the echo ...; will generate text that will be downloaded by the browser on the user’s machine, so it will only run after the download is completed, Exit only stops any process on the server-side after the echo used there, but has nothing to do with the front-end either.

About javascript forwarding read more on: /a/105373/3635

Browser other questions tagged

You are not signed in. Login or sign up in order to post.