vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Setting temp cookies of 15secs (https://vborg.vbsupport.ru/showthread.php?t=39007)

Jawelin 05-24-2002 05:08 PM

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

Admin 05-25-2002 04:52 AM

Use PHP4's sessions, sounds perfect for what you're trying to do.

Jawelin 05-25-2002 06:46 AM

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

Admin 05-25-2002 07:06 AM

Nope, sorry, I haven't had much experience with sessions in PHP.

Jawelin 05-27-2002 09:49 AM

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:

$myvar=0

Well. If I increment it in a certain script, shall it result increased also from all the other scripts ?
So, the same user should 'see' $myvar=1 ... Shouldn't it?

And, for other users ? How will that var be valued ?

Thanks

Logician 05-27-2002 10:28 AM

Hi Jawelin,

Quote:

Originally posted by Jawelin
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:

$myvar=0

Well. If I increment it in a certain script, shall it result increased also from all the other scripts ?
So, the same user should 'see' $myvar=1 ... Shouldn't it?

And, for other users ? How will that var be valued ?

everytime a PHP script is run by a user, it runs with default variable values. So if you change a variable value inside a script, change will apply only to user who triggered the script, not to other users running the same script.

If you want to keep its new value, you have to save it somewhere (file, MYSQL etc.)

Regards,
Logician

Jawelin 05-27-2002 10:53 AM

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

Logician 05-27-2002 02:33 PM

Quote:

Originally posted by Jawelin
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...)

If the variable is defined inside a function (and you want its value preserved when function (but not the script, "function"!) is run again), you have 2 choices:

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?

Jawelin 05-28-2002 03:57 PM

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

Logician 05-28-2002 04:15 PM

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..


All times are GMT. The time now is 07:32 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01018 seconds
  • Memory Usage 1,740KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete