Question

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 :)

Était-ce utile?

La solution 2

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.

Autres conseils

Looks like you have a copy paste from some online tutorial you have to use your username, password and database names in this functions

mysql_connect("localhost","username","password");
mysql_select_db("database",$connection) 

If you post your entire code and just change the username and password we can help you better.

It says error on line 10 - but we can't see easily what line 10 is, given you have sliced your code.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top