Reputation: 45
When I run the php code I was not able to go to the other page. Here is the php snippet...
}
if (headers_sent()) {
die("Redirect failed. Please click on this link: <a href=...>");
}
else{
?>
<!-- Script to redirect to other url...-->
<script type='text/javascript'>
window.location.href = 'http://<?php echo
$_SERVER['SERVER_NAME'].":8001/".$url ?>';
</script>
<?php
ob_end_flush();
exit();
?>
...
Firebug output:
Response
<script type='text/javascript'>
window.location.href = 'http://localhost:8001
/pall_oneless.php?uid=6fe9b73027';
</script>
Response headers as shown in Firebug:
Connection close Content-Type
text/html Host
localhost:8001 X-Powered-By
PHP/5.5.9-1ubuntu4.17 view source Accept text/html, /; q=0.01 Accept-Encoding
gzip, deflate Accept-Language
en-US,en;q=0.5 Connection keep-alive Content-Length 91 Content-Type
application/x-www-form-urlencoded; charset=UTF-8 Cookie PHPSESSID=fnckn52eoai0dqdmdutsd3ljm6 Host
localhost:8001 Referer
http://localhost:8001/login.php User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0 FirePHP/0.7.4 X-Requested-With
XMLHttpRequest x-insight
activate
Upvotes: 1
Views: 53
Reputation: 40946
If all you want to do there is redirect, there is no need to user JavaScript. Use headers and it will be even faster: change your else
clause to
else{
$newLocation = 'http://'.$_SERVER['SERVER_NAME'].':8001/'.$url;
header("Location: $newLocation");
exit;
}
Upvotes: 1
Reputation: 2072
That is not how you do a redirect in php. That's in javascript. In php you do:
...
else {
header('Location: http://'.$_SERVER['SERVER_NAME'].':8001/'.$url);
exit;
}
Upvotes: 0