I want to redirect a page automatically in PHP
Logout.php:
<?php
include "base.php";
$_SESSION = array(); session_destroy();
?>
<meta http-equiv="refresh" content="=0;URL=index.php" />
Where base.php calls the database and starts the session:
<?php
session_start();
$dbhost = "localhost";
$dbname = "login";
$dbuser = "root";
$dbpass = "";
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
?>
When pressing logout, I am not getting back to index.php
.
As far as I know,
HTML
,JavaScript
andPHP
provide their own way of page / header redirection. Here are three examples, showing how to redirect tohttp://google.com
#
JavaScript:
#
HTML:
#
PHP:
This should work, you had an extra
=
before0
:Linky https://en.wikipedia.org/wiki/Meta_refresh
Meta refresh syntax is slightly wrong
More details here http://en.wikipedia.org/wiki/Meta_refresh
The cleaner way is to send a http redirect header
More details here http://en.wikipedia.org/wiki/HTTP_301
logout.php
Concerning absolute URIs in redirects W3C says
14.30 Location
Source: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
you can put this on your PHP code:
Note that as per all headers, this must be placed before any output (even whitespace).