|
|
|
|
![]() ![]() |
Oct 9 2006, 06:46 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 202 Joined: 7-November 05 Member No.: 13,928 |
i have many pool (quiz) modules on my site with the information taken from a database. The modules are processed by the same function with different parameters and i need to save the pool's status to prevent a user vote several times. I do this setting $_SESSION[ 'variable' ] to 1 , variable being the name of the quiz, which is taken from the database. So i get to having a code like this:
.................... $name= $row->quiz_name; $_SESSION[$name]=1 The problem is that if i call $_SESSION[$name] from another part of the site (another page) the variable is always zero and if i check the $name by writting CODE echo '$_SESSION['. $name .']= '.$_SESSION[$name] I get as output $_SESSION[]=0 If i store the value in a variable like this $_SESSION['quiz_1']=1 then it shows as this everywhere. One problem could be that that the $name, actually defined in a function, isn't global and thus it exists only in the function but even if i declare it global $name in the function it still doesn't show up on another page. But in the function the variable $name is generated every time the function is called and it's the same for one quiz but it's value isn't stored even among two calls of the function. If i vote for one option then the variable is set to 1 then i refresh the page and it votes again. Can u give me some advice as this is the first time i'm using this in php... |
|
|
|
Oct 9 2006, 05:50 PM
Post
#2
|
|
|
A clever man learns from his own mistakes, a WISE man learns from those of OTHERS ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 1,028 Joined: 12-April 06 From: Essex, UK Member No.: 21,719 |
humm, abit confusing but i get the idea that the session variable name isnt stored properly.
The first thing i notice is that you have "$_SESSION['$name']" personally i have never used a variable inside an array like that so you might want to try it without the dollar sign so its not a variable within an array. That might help. I think what you are trying to do with the cade is you have a variable called $name which contains a users name and you want this into a session variable? if so just have code like: CODE $_SESSION['name'] = $name; but either way try dropping the dollar sign and putting "name" into single ' ' quotes that might help. Its what i would try first. |
|
|
|
Oct 10 2006, 08:10 AM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 202 Joined: 7-November 05 Member No.: 13,928 |
i solved the problem the variable creation was put in an IF statement not always true so not always creating it. God it took me 3 hours to find this
not really, it's ok putting the variable inside like $_SESSION[ $name ] and becouse in my script this thing is inside a function called by many pages every new call needs a new name so the name is generated inside the function, and also is verified inside the function with the generated name: $id = $_POST['id'] ; -from the form $session = $name.$id ; if ( $_SESSION[$session]=1 )...than the visitor has been here before and did once whatever the function does This post has been edited by realthor: Oct 10 2006, 08:16 AM |
|
|
|
Oct 12 2006, 01:51 PM
Post
#4
|
|
|
A clever man learns from his own mistakes, a WISE man learns from those of OTHERS ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 1,028 Joined: 12-April 06 From: Essex, UK Member No.: 21,719 |
QUOTE not really, it's ok putting the variable inside like $_SESSION[ $name ] i learn something new everyday! Glad to see you got it in the end |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 10th October 2008 - 06:55 PM |