开发者

Undefined variable SESSION

I am using php $_SESSION like this

 $_SESSION['original_referrer_location']

but i keep getting this error

Notice: Undefined variable: _SESSION in /var/www/m/inc/referrer.php on line 3

so I added this to the top of my script

ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(0, '/');
session_start();

and all is good.

Is there a way to turn on sessions for good because having to add this on top of any s开发者_运维技巧cript that needs a session is kind of redundant....i went to php.ini but there are many calls that start with session...any ideas on what i need to change ...I am on ubuntu 10.10/php5 in case that matters


There is:

http://www.php.net/manual/en/session.configuration.php#ini.session.auto-start

But i wouldn't recommend using it. For example you would like to store whole object in session, to do it you would need to include file with class declaration first, otherwise unserialized object will be of incomplete class.

Other way is to auto-prepend file that sets some basic configuration and starts session


Yes

session.auto.start

session.auto_start boolean session.auto_start specifies whether the session module starts a session automatically on request startup. Defaults to 0 (disabled).


When you want to use sessions, remember to call session_start() before the HTML tag

<?php session_start(); ?>

<html>
<body>
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜