doushun1904 2013-03-22 00:50
浏览 93
已采纳

Php登录,无法继续会话

So basically I am trying to run a login system and use the user's data to update a page in real time, unfortunately I cannot continue the session and every time I try to echo the user nothing happens, here is my code for logging in.

    <?php

$host="IPADRESS"; // Host name 
$username="web11-sign-up"; // Mysql username 
$password="w0lfbane01#"; // Mysql password 
$db_name="web11-sign-up"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// 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($mypassword);
$mypassword = 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"
$_SESSION["$myusername"];
$_SESSION["$mypassword"]; 
header("location:Scene-Selection/");
}
else {
echo "Wrong Username or Password";
}
?>

I did not realize that this section was not working until I started on another section of the site. I could not retrieve any information from the database.

  • 写回答

3条回答 默认 最新

  • du6029076877 2013-03-22 00:52
    关注

    Are you starting your sessions at the top of each page?

    Make sure you're calling session_start(); somewhere at the top of each page you'd like to use sessions on.

    I personally include an application.php at the top of each page - which contains DB connection details, session_start();, global functions etc...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案