社交引擎中的PHP会话

时间:2021-10-31 08:53:37

I have this query in mysql in a php page:

我在php页面的mysql中有这个查询:

mysql_query("INSERT INTO tz_todo SET text='".$text."', 
                                     position = ".$position.", 
                                     user_id=".$_SESSION['user_id'].", 
                                     view_stat=0");

I tried to echo the query and the result is this:

我试图回应查询,结果如下:

INSERT INTO tz_todo SET text='trial text', position = 21, user_id=, view_stat=0

it seems that it can't get the session value of user_id.

它似乎无法获得user_id的会话值。

And $_SESSION['user_id'] is not working in social engine. How to correct this? I also made a localhost version in my xampp and everything is fine but when I converted it into social engine, session is not working.

并且$ _SESSION ['user_id']无法在社交引擎中运行。怎么纠正这个?我也在我的xampp中创建了一个localhost版本,一切都很好但是当我将它转换为社交引擎时,会话无效。

5 个解决方案

#1


2  

In any page where you are using session objects, place this code at the beginning of the file:

在使用会话对象的任何页面中,将此代码放在文件的开头:

if(!isset($_SESSION)){session_start();}

This way if the session is not already started, it starts it; otherwise it ignores the session start if the sesion is already started. This is important because calling session_start() if session is started already can sometimes cause errors.

这样,如果会话尚未启动,则启动它;否则,如果sesion已经启动,它将忽略会话开始。这很重要,因为如果会话已启动,则调用session_start()有时会导致错误。

#2


1  

That's how I get my user id through session

这就是我通过会话获取用户ID的方式

session_start();

$userID = $viewer->getIdentity();

$_SESSION['user_id'] = $userID;

echo $_SESSION['user_id'];

#3


1  

Using session to store the user_id is totally wrong. To gain a user_id try

使用session来存储user_id是完全错误的。获取user_id尝试

$viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity(); (or $user->getIdentity if you have another user's object).

$ viewer_id = Engine_Api :: _() - > user() - > getViewer() - > getIdentity(); (如果你有另一个用户的对象,则为$ user-> getIdentity)。

If you still need to use session for storing this data, use Zend-approach.

如果仍需要使用会话来存储此数据,请使用Zend-approach。

#4


0  

session_start(); 
$_SESSION["test"] = "hello world";
session_start();
echo $_SESSION["test"];

does above code work ? if not, check your session.save_path in the php.ini

以上代码有效吗?如果没有,请检查php.ini中的session.save_path

NOTE: to retain this variable remember to call session_start() on each php script/page before calling for the variable from the session.

注意:要保留此变量,请记住在从会话中调用变量之前,在每个php脚本/页面上调用session_start()。

#5


0  

Yoy might be forget to start your session at the top of the page

Yoy可能会忘记在页面顶部开始你的会话

<?php if(!isset($_SESSION)){ session_start(); } ?>

<?php if(!isset($ _ SESSION)){session_start(); }?>

$_SESSION['user_id'] might not stored a value. check your login page (Basically after login session variables will set) or after register weather you assigned a value to that session variable..

$ _SESSION ['user_id']可能未存储值。检查您的登录页面(基本上在设置登录会话变量之后)或在注册天气之后您为该会话变量分配了一个值。

setting a value to a session variable :

将值设置为会话变量:

$_SESSION['user_id'] = "1234567";

$ _SESSION ['user_id'] =“1234567”;

#1


2  

In any page where you are using session objects, place this code at the beginning of the file:

在使用会话对象的任何页面中,将此代码放在文件的开头:

if(!isset($_SESSION)){session_start();}

This way if the session is not already started, it starts it; otherwise it ignores the session start if the sesion is already started. This is important because calling session_start() if session is started already can sometimes cause errors.

这样,如果会话尚未启动,则启动它;否则,如果sesion已经启动,它将忽略会话开始。这很重要,因为如果会话已启动,则调用session_start()有时会导致错误。

#2


1  

That's how I get my user id through session

这就是我通过会话获取用户ID的方式

session_start();

$userID = $viewer->getIdentity();

$_SESSION['user_id'] = $userID;

echo $_SESSION['user_id'];

#3


1  

Using session to store the user_id is totally wrong. To gain a user_id try

使用session来存储user_id是完全错误的。获取user_id尝试

$viewer_id = Engine_Api::_()->user()->getViewer()->getIdentity(); (or $user->getIdentity if you have another user's object).

$ viewer_id = Engine_Api :: _() - > user() - > getViewer() - > getIdentity(); (如果你有另一个用户的对象,则为$ user-> getIdentity)。

If you still need to use session for storing this data, use Zend-approach.

如果仍需要使用会话来存储此数据,请使用Zend-approach。

#4


0  

session_start(); 
$_SESSION["test"] = "hello world";
session_start();
echo $_SESSION["test"];

does above code work ? if not, check your session.save_path in the php.ini

以上代码有效吗?如果没有,请检查php.ini中的session.save_path

NOTE: to retain this variable remember to call session_start() on each php script/page before calling for the variable from the session.

注意:要保留此变量,请记住在从会话中调用变量之前,在每个php脚本/页面上调用session_start()。

#5


0  

Yoy might be forget to start your session at the top of the page

Yoy可能会忘记在页面顶部开始你的会话

<?php if(!isset($_SESSION)){ session_start(); } ?>

<?php if(!isset($ _ SESSION)){session_start(); }?>

$_SESSION['user_id'] might not stored a value. check your login page (Basically after login session variables will set) or after register weather you assigned a value to that session variable..

$ _SESSION ['user_id']可能未存储值。检查您的登录页面(基本上在设置登录会话变量之后)或在注册天气之后您为该会话变量分配了一个值。

setting a value to a session variable :

将值设置为会话变量:

$_SESSION['user_id'] = "1234567";

$ _SESSION ['user_id'] =“1234567”;