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
and PHP
provide their own way of page / header redirection. Here are three examples, showing how to redirect to http://google.com
JavaScript:
<script type="text/javascript">
window.location = "http://google.com";
</script>
HTML:
<meta http-equiv="refresh" content="0; URL='http://google.com'"/>
Note The 0 in
content="0;
, is a value for seconds. It tells the browser how many seconds it should wait before starting the redirect.
PHP:
<?php
header('Location: http://www.google.com');
Note A PHP
header()
must be Always be placed before outputting anything to the browser; even a single empty space. Otherwise, it will cause the infamous "header already sent" errors.
This should work, you had an extra =
before 0
:
<meta http-equiv="refresh" content="0;URL=index.php" />
Linky https://en.wikipedia.org/wiki/Meta_refresh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With