Try changing:
header("Location : blabla")
^
|
(whitespace)
To
header("Location: blabla")
Answer from BuraCULa on Stack Overflowhttp redirect - PHP header(Location: ...): Force URL change in address bar - Stack Overflow
PHP Redirect to different url using header("Location:") does not work
http redirect - Back to previous page with header( "Location: " ); in PHP - Stack Overflow
PHP Header Location not working - PHP - SitePoint Forums | Web Development & Design Community
Videos
Try changing:
header("Location : blabla")
^
|
(whitespace)
To
header("Location: blabla")
Well, if the server sends a correct redirection header, the browser redirects and therefore "changes the url". It might be a browser issue, then. I don't know if it has anything to do with it, but you should not send a relative url in the location header ("HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. ", http://php.net/manual/en/function.header.php), and "location" must be capitalized, like:
header('Location: http://myhost.com/mypage.php');
Headers must be set before any data is transmitted, so you can't just stick them in the middle of a file. Quoting the the manual:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
So at the very least you'll need to rewrite your file to:
<?php
header("Window-target: _parent");
header("Location: https://www.w3schools.com/");
?>
<!doctype html>
...
Also, never sleep() in an http(s) response: that response should finish as fast as it can, no matter what content it needs to generate. Sleep has no place in (really any) PHP code.
A combination of PHP and JS seems to be the easiest solution. But that might be only my opinion. I tried to document the code as good as possible, so others can understand it:
<?php
function redirect() { // Create some JS code which will pause for 3 seconds and execute the move function afterwards. This Function will redirect the user
echo "<script>";
echo "function move() {window.location.replace('http://www.w3schools.com');}";
echo "setTimeout(move, 3000);";
echo "</script>";
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Test2</h1>
<?php
echo "<p>You will be redirected after the code has been executed!</p>";
// Run actual code
redirect(); // Redirect using JS code
?>
</body>
</html>
try:
header('Location: ' . $_SERVER['HTTP_REFERER']);
Note that this may not work with secure pages (HTTPS) and it's a pretty bad idea overall as the header can be hijacked, sending the user to some other destination. The header may not even be sent by the browser.
Ideally, you will want to either:
- Append the return address to the request as a query variable (eg. ?back=/list)
- Define a return page in your code (ie. all successful form submissions redirect to the listing page)
- Provide the user the option of where they want to go next (eg. Save and continue editing or just Save)
Its so simple just use this
header("location:javascript://history.go(-1)");
Its working fine for me
http_redirect is basically a helper function, making it easier to use header location by allowing you to pass an array for GET data.
- Header in PHP
header() function sends a raw HTTP header to a client.
<?php
header("HTTP/1.0 404 Not Found");
?>
The above (taken from the PHP documentation) sends a 404 header back to the client.
- HTTP Redirect
Redirect to the given url.
<?php
http_redirect("relpath", array("name" => "value"), true, HTTP_REDIRECT_PERM);
?>
The above (taken from the PHP documentation) : Output
HTTP/1.1 301 Moved Permanently
X-Powered-By: PHP/5.2.2
Content-Type: text/html
Location: http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc
Redirecting to <a href="http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc">http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc</a>.