The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Setting temp cookies of 15secs
Hi. I would need to store in the client's browser a temp variable.
As asked HERE I tried different ways to do this, but never managed. Do you know some way to set and read a cookie within a function ? Actually I would need to know if an user, within a session, has done something. When he does it first, I could set a global/cookie var somewhere, but would know (and eventually change) that value from any php script. And that value should expire with that user's session... How could I do something like ? Thanks a lot. Bye |
#2
|
||||
|
||||
Use PHP4's sessions, sounds perfect for what you're trying to do.
|
#3
|
|||
|
|||
Excuse me but already checked that argument on php.net ...
And I didn't manage to implement and use a session var. Have you already done something about ? Thanks |
#4
|
||||
|
||||
Nope, sorry, I haven't had much experience with sessions in PHP.
|
#5
|
|||
|
|||
Thanks the same.
A general question: if I define a numeric variable in global.php, it should become a global (visible by all phps) one. For instance, PHP Code:
So, the same user should 'see' $myvar=1 ... Shouldn't it? And, for other users ? How will that var be valued ? Thanks |
#6
|
||||
|
||||
Hi Jawelin,
Quote:
If you want to keep its new value, you have to save it somewhere (file, MYSQL etc.) Regards, Logician |
#7
|
|||
|
|||
Perfect! It's exactly what I would for that variable! (read above)
This way, such variable should be valued per-user and per-session (I guess when that user's session expires, variable would loose its value... ???): exactly what I asked before to FireFly... Well. It doesn't work.... Whatever user saw that incremented variable (incremented within a function he runs), that variable is ALWAYS 0 ... (note: of course I globalized that variable within that function, even I tried to ++ it outside...) Bah! Thnx |
#8
|
||||
|
||||
Quote:
1- "Global"ize the variable and return it back to script AFTER function ends. 2- Simpler way: define it as a static varible inside the function: static $a = 1; Then $a's value will be preserved when same user comes to the same function again. Of course this doesnt apply if the script is rerun! It's preserved until the script run ends. I think this is already what you wanted? |
#9
|
|||
|
|||
I would that $a = 1 is mantained till that user is logged in that session.
I mean, if he reruns the same script after some time (let's say, two hours), that variable should be reset back to 0, before, then incremented. Is it what you said ? Thanks |
#10
|
||||
|
||||
no, I meant 'static' command will preserve the variable value inside the function but only for that run of the script.
If you want to preserve the value for the user's session, you need to use it as a session variable: session_start(); //starts a session $id=session_id(); //your session id that you started $a=1; //your variable session_register("a"); //makes your variable a session var. and now call all your relevant scripts with "$id" (session variable) to keep your session (hence session variables). For example if a form returns some info back to your same script, use this: <form METHOD="POST" ACTION="yourscript.php?=$id"> By this way your $a is preserved for the entire session for this user.. Hope this helps.. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|