I am having issues with my PHP logout script I have the below code:
<?php
session_start();
//redirect function
function returnheader($location){
$returnheader = header("location: $location");
return $returnheader;
}
$connection = mysql_connect("localhost","username","password") OR die(mysql_error());
$db_select = mysql_select_db("database",$connection) OR die(mysql_error());
// destroy cookies and sessions
setcookie("userloggedin", "");
$username = "";
session_destroy();
//redirect
returnheader("index.php");
?>
I keep getting the below error:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'loginuser'@'localhost' (using password: YES) in logout.php on line 10
Access denied for user 'loginuser'@'localhost' (using password: YES)
can anyone help I am new to php and may of bitten off more than i can chew :)
It would be better to include a file which contains database connection stuff instead of writing them on every page. Apart from that, a logout script like this should be sufficient enough:
<?php
session_start(); // start a session first, else you cannot destroy/unset it
session_destroy(); // destroy all sessions
header('location:index.php'); // redirect
?>
Also, as @chandresh_cool said, I hope you didn't really use "username", "password" and "database" as credentials.