php会话立即被破坏

时间:2013-11-28 05:44:11

标签: 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]

2 个答案:

答案 0 :(得分:0)

只需在session_start();

下添加此代码即可
<?php session_start();
ob_start();
?>

答案 1 :(得分:0)

您可以使用

增加会话默认超时
      session_set_cookie_params(3000); 

   Then start your session this will allow you to increase session timout you
   don't have to edit php.ini