Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2002, 05:08 PM
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Posts: 557
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 05-25-2002, 04:52 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use PHP4's sessions, sounds perfect for what you're trying to do.
Reply With Quote
  #3  
Old 05-25-2002, 06:46 AM
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Posts: 557
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #4  
Old 05-25-2002, 07:06 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nope, sorry, I haven't had much experience with sessions in PHP.
Reply With Quote
  #5  
Old 05-27-2002, 09:49 AM
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Posts: 557
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 05-27-2002, 10:28 AM
Logician's Avatar
Logician Logician is offline
 
Join Date: Nov 2001
Location: inside vb code
Posts: 4,449
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #7  
Old 05-27-2002, 10:53 AM
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Posts: 557
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #8  
Old 05-27-2002, 02:33 PM
Logician's Avatar
Logician Logician is offline
 
Join Date: Nov 2001
Location: inside vb code
Posts: 4,449
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #9  
Old 05-28-2002, 03:57 PM
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Posts: 557
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 05-28-2002, 04:15 PM
Logician's Avatar
Logician Logician is offline
 
Join Date: Nov 2001
Location: inside vb code
Posts: 4,449
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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..
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05361 seconds
  • Memory Usage 2,253KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete