会话在1页加载后立即销毁

时间:2013-11-28 06:27:46

标签: php session

这是一个重新发布,因为我想出了如何发布我的代码。请不要生气管理员! 当我将它们设置为瞬间,然后它们被销毁时,似乎会话工作。 这是我的phpinfo页面,谁能看到问题? 我无法访问phpini文件。 你能检查我的cookie设置并告诉我是否可以使用它们吗? http://cksgrill.net/phpinfo.php

[code]

<!DOCTYPE html>
<script src="/javascript/header.js"></script>
<?

session_set_cookie_params(3000); 
session_start();
ob_start();
ini_set('session.gc_maxlifetime', 6 * 60 * 60);
$session_expiration = time() + 3600 * 24 * 2;
if((($_POST['name'])and($_POST['password']))or(($_POST['name']!="")and($_POST['password']!="")))
{
    $_SESSION['name']=$_POST['name'];
    $_SESSION['password']=$_POST['password'];
    echo $_SESSION['name'];
    echo $_POST['name'];
    echo $_SESSION['password'];
    echo $_POST['password'];
}


// redifine variables for different server
require_once "mysqlconfig.php";  
require_once "textprep.php";  

// connect to database
global $connection;
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); 
if (!$connection)
{
    die("Database connection failed: " . mysql_error());
}

// select database
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select)
{
    die("Database selection failed: " . mysql_error());
}

//check if logged in
$result = mysql_query("SELECT * FROM admin");
if (!$result)
{
    die("Database query failed: " . mysql_error());
}

// get table names as mysql feedback
$i=0;
while ($row = mysql_fetch_array($result)) 
{
    $name[$i]=$row['name'];
    $password[$i]=$row['password'];
    $rank[$i]=$row['rank'];

    //echo "\$name[$i]=".$row['name'];
    //echo "\$password[$i]=".$row['password'];
    //echo "\$rank[$i]=".$row['rank'];

    $i++;
}

//check if logged in
$log=false;
for($j=0;$j<$i;$j++)
{
    //echo "<p>(".$name[$j]."==".$_SESSION['name'].")and(".$password[$j]."==".$_SESSION['password'].")</p>";
    if(($name[$j]==$_SESSION['name'])and($password[$j]==$_SESSION['password']))
    {
        $log=true;
        echo logged." ".$log;
    }
}
if($log==true)
{
[/code]

1 个答案:

答案 0 :(得分:0)

你必须在任何输出之前开始会话

session_start();