douzhou7124 2013-04-17 08:01
浏览 57

无法从SESSION获取变量

I'm having a problem with my school project. I've asked both my teacher and classmates for help but none of them doesn't know what to do.

I've made a browser based game, and obviously it needs to have users. And this is where the problem is.

When i log in and proceed to the authenticate page, it extracts info from POST just fine, but when i insert the info into SESSION in authenticate and then go to the homepage index, it refuses to get the SESSION information and i just get an error.

NOTE, design2.php doesnt have anything to do with the log in process.

Here's the code:

Login.php

<?php
include_once'design2.php';
?>

<div id="center">

<form method="POST" action="authenticate.php">
User Name <input id="input" type="text" name="player" size="21">
Password <input id="input" type="password" name="password" size="21">
<br>
<input type="submit" value="Login" name="submit">

<br><br>Not Registered? <a id='underlinelink' href='register.php'>Register</a>

Authenticate.php

<?php
include_once 'connect.php';
?>
<div id="center">
<?php
if (isset($_POST['submit']))
{
  $player=$_POST['player'];
  $password=$_POST['password'];
  $player=strip_tags($player);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "select name, password from players where name='$player' and password='$password'";
  $result = mysql_query($query) or die("Could not query players");
  $result2 = mysql_fetch_array($result);
  if ($result2)
  { 
    $_SESSION['player'] = $player;

    echo "<big>Logged in successfully<br>";
    echo "<A id='underlinelink' href='index.php'>Continue</a></big>";
  }
  else
  {
   echo "<big>Wrong username or password.<A id='underlinelink' href='login.php'>Try Again</a></big>";
  }
}
?>
</div>

Design.php (This is on every single webpage on my site)

<?php
include_once 'connect.php';
?>

<link href="stilark.css" rel="stylesheet" type="css" />

<?php
session_start();  

if(isset($_SESSION['player']))
    $player = $_SESSION['player'];
else
    echo "could not logg in, <a href='login.php'>Go back</a>"; 
    exit;

$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

?>

Please help, i really need to get this done before its due.

  • 写回答

3条回答 默认 最新

  • drwf69817 2013-04-17 08:05
    关注

    Your session_start() must be BEFORE any output

    <?php
    session_start(); 
    include_once 'connect.php';
    ?>
    
    <link href="stilark.css" rel="stylesheet" type="css" />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题