SESSION变量有问题...... [英] Problem with SESSION variables...

查看:73
本文介绍了SESSION变量有问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我是非常新的PHP,我有一个问题,我无法找到

的解决方案。我遇到了会话变量的问题,我想要一些

变量来维护它们之间的值,即不同的PHP脚本被调用。我已经阅读了在线手册,这里有一个例子来自

它对我不起作用,它很好地说明了我的问题。


文件1, index.php


<?php

// index.php


session_start();


echo''< br />欢迎来到第1页'';


$ _SESSION [''favcolor''] =' 'green'';

$ _SESSION [''animal''] ='''cat'';

$ _SESSION [''time''] = time() ;

//如果会话cookie被接受,则工作

echo''< br />< a href =" page2.php"> page 2< / a>'';


//或者如果需要可以传递会话ID

echo''< br />< a href =" page2.php?''。 SID。 ''">第2页< / a>'';

?>


文件2,page2.php


<?php

// page2.php


session_start();


echo''< br />欢迎来到第2页< br />'';


echo $ _SESSION [''favcolor'']; //绿色

echo $ _SESSION [''animal'']; //猫

回音日期('Y md H:i:s'',$ _SESSION [''time'']);


/ /你可能想在这里使用SID,就像我们在page1.php中所做的那样

echo''< br />< a href =" index.php"> page 1< / a>'';

?>


我没有输出,除了显示1970 bla bla


我在Redhat 9.0机器上运行apache 2.0.48,PHP 4.3.3。我没有

触及php.ini中的register_globals,它已经关闭了。可能是什么问题

在这里?任何帮助都会非常感激,我被卡住....


Thanx


/ ZoombyWoof

Hi. Im very new to php, and I have a problem here that I cant find the
solution for. I have problems with session variables, I want some
variables to maintain their value between different php script that is
being called. I have read the online manual, and here is an example from
it that doesnt work for me, it illustrates very well my problem.

File 1, index.php

<?php
// index.php

session_start();

echo ''<br />Welcome to page #1'';

$_SESSION[''favcolor''] = ''green'';
$_SESSION[''animal''] = ''cat'';
$_SESSION[''time''] = time();
// Works if session cookie was accepted
echo ''<br /><a href="page2.php">page 2</a>'';

// Or maybe pass along the session id, if needed
echo ''<br /><a href="page2.php?'' . SID . ''">page 2</a>'';
?>

File 2, page2.php

<?php
// page2.php

session_start();

echo ''<br />Welcome to page #2<br />'';

echo $_SESSION[''favcolor'']; // green
echo $_SESSION[''animal'']; // cat
echo date(''Y m d H:i:s'', $_SESSION[''time'']);

// You may want to use SID here, like we did in page1.php
echo ''<br /><a href="index.php">page 1</a>'';
?>

I get no output, except the date which shows 1970 bla bla

I have apache 2.0.48, PHP 4.3.3 running on a Redhat 9.0 box. I have not
touched the register_globals in php.ini, it''s Off. What can be the problem
here ? Any help would be much appreciated, I''m stuck....

Thanx

/ZoombyWoof

推荐答案

_SESSION [''favcolor''] =''green'';
_SESSION[''favcolor''] = ''green'';


_SESSION [ ''animal''] =''cat'';
_SESSION[''animal''] = ''cat'';


_SESSION [''time''] = time();

/ /如果接受会话cookie,则工作

echo''< br />< a href =" page2.php"> page 2< / a>'';


//或者可以传递会话ID,如果需要的话

echo''< br />< a href =" page2.php?'' 。 SID。 ''">第2页< / a>'';

?>


文件2,page2.php


<?php

// page2.php


session_start();


echo''< br />欢迎来到第2页< br />'';


echo
_SESSION[''time''] = time();
// Works if session cookie was accepted
echo ''<br /><a href="page2.php">page 2</a>'';

// Or maybe pass along the session id, if needed
echo ''<br /><a href="page2.php?'' . SID . ''">page 2</a>'';
?>

File 2, page2.php

<?php
// page2.php

session_start();

echo ''<br />Welcome to page #2<br />'';

echo


这篇关于SESSION变量有问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆