Jump to content

Session variable becoming linked to post variable


sneiland

Recommended Posts

This is probably an obvious one but i cant see why i am getting this problem.

 

Basically i have a user id stored in session variable eg user_id =1. I have a simple forum that i created myself that inserts this session variable into the db with the persons entry. eg insert into forum value (session[user_id],'$_post['content']);

 

This is all working fine until i go to edit this post from say the moderator account. I set the user_id for the "replace into db" initially to my session value unless i have selected to edit someone elses post, then i set it to the value submited back from the <form action=self>

 

i get as far as selecting the contents from db only for the session variable holding my id to change to the value of the user_id selected from the db.

 

//if self submit

//if this is a new entry into forum then get my id from session variable

if($_POST['user_id']=="")

{

  $user_id=$_SESSION['user_id'];

}

else

{

    //get user value from posted form

    $user_id=$_POST['user_id'];

}

 

//if this is not a new post get the current values in table

$query="

SELECT topic_id, topic_subject, user_id FROM forum WHERE topic_id = 1;

if($result=queryDB($query))

{

  while($resultrow=mysql_fetch_array($result))

  {

    $debug.="D Session user_id: ".$_SESSION[user_id]."<br />";

//at this point my session id is one

    $topic_id=$resultrow['topic_id'];

    $subject=$resultrow['topic_subject'];

    $user_id=$resultrow['user_id'];

    $debug.="E Session user_id: ".$_SESSION[user_id]."<br />";

//at this point my session variable has changed to two the value stored in $user_id

}

}

 

//replace into forums

If you have access to php.ini, ensure that register_globals isn't on.  Also, when you are setting the session, are you calling register_session()?  If so, then $_SESSION['user_id'] would become a reference to the variable $user_id.  Whenever $user_id is changed, $_SESSION['user_id'] would be changed as well.

 

If you have access to php.ini, ensure that register_globals isn't on.  Also, when you are setting the session, are you calling register_session()?  If so, then $_SESSION['user_id'] would become a reference to the variable $user_id.  Whenever $user_id is changed, $_SESSION['user_id'] would be changed as well.

 

You will have to set $_SESSION['user_id']=$user_id; to a session then you can use it ok.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.