php 会话立即销毁 [英] php sessions destroyed instantly
本文介绍了php 会话立即销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎会话在我设置它们时起作用,然后它们被销毁.这是我的 phpinfo 页面,有人能看到问题吗?我无权访问 phpini 文件.你能检查我的 cookie 设置并告诉我是否可以使用这些设置吗?http://cksgrill.net/phpinfo.php
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]
推荐答案
您可以使用
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
这篇关于php 会话立即销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文