我的PHP注销脚本有问题,我有以下代码:
<?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");
?>我一直收到以下错误:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'loginuser'@'localhost' (using password: YES) in logout.php on line 10拒绝用户'loginuser'@'localhost‘的访问(使用密码: YES)
有人能帮我吗?我是php新手,可能吃不了那么多东西:)
发布于 2013-05-16 17:32:26
最好包含一个包含数据库连接内容的文件,而不是将它们写在每个页面上。除此之外,像这样的注销脚本应该足够了:
<?php
session_start(); // start a session first, else you cannot destroy/unset it
session_destroy(); // destroy all sessions
header('location:index.php'); // redirect
?>另外,正如@chandresh_cool所说,我希望你不会真的使用“用户名”、“密码”和“数据库”作为凭证。
发布于 2013-05-16 17:27:58
看起来你有一个从一些在线教程复制粘贴,你必须使用你的用户名,密码和数据库名称在此函数
mysql_connect("localhost","username","password");
mysql_select_db("database",$connection) 发布于 2013-05-16 17:33:38
如果你发布了你的全部代码,只是修改了用户名和密码,我们可以帮你做得更好。
它在第10行显示错误--但是我们不能很容易地看到第10行是什么,因为您已经对代码进行了切片。
https://stackoverflow.com/questions/16583672
复制相似问题