我在社交网络上工作,当我尝试触发session_start()时;这是行不通的。我已经阅读了一些其他问题,显然是session_start();已被弃用。
这是我的index.php:
<?php
session_start();
if(!$_SESSION["myusername"]){
include("./assets/inc/nli-home.inc.php");
}
else {
include("./assets/inc/connect.inc.php");
include("./assets/inc/header.inc.php");
include("./assets/inc/posts.inc.php");
include("./assets/inc/header2.inc.php");
include("./assets/inc/footer.inc.php");
}
?>
这是checklogin.php的结尾,其中index.php是从以下位置重定向的:
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes(md5($mypassword));
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$myusername = $_SESSION["myusername"];
$myusername = $_SESSION["mypassword"];
header("location:index.php");
}
else {
echo "Wrong Username or Password";
}
?>
真的很感激一些帮助!
答案 0 :(得分:1)
checklogin.php
也需要session_start()
。
此外,在将任何输出发送到浏览器之前,必须先调用session_start()
。页面上是否有前导"space"
(在打开PHP标记之前)?