download1323 2013-11-28 06:27
浏览 49

会话在1页加载后立即销毁[重复]

This question is an exact duplicate of:

this is a repost becuase i figured out how to post my code. please dont get mad admins! It seems that sessions work when I set them for an instant, and then they are destroyed. Here is my phpinfo page, can anyone see the problem? I don't have access to the phpini file. Can you check my cookie settings and tell me if I can use those instead? 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]
</div>
  • 写回答

1条回答 默认 最新

  • doudengshen5591 2013-11-28 06:31
    关注

    you have to start session before anything output

    session_start();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c