Jump to content

PHP Variables sticking


Janus13

Recommended Posts

I've been trying to trace down a strange problem on some of my php pages where the page wouldn't carry variables from a sql query. The variables would end up being the logged on user's variables. My question, is once you set a variable in a page, does it clear when you leave that page or do you have to unset it?

Also, if I set a session variable of username, and then define a variable of $username, would those conflict?
Link to comment
https://forums.phpfreaks.com/topic/4128-php-variables-sticking/
Share on other sites

[!--quoteo(post=351766:date=Mar 5 2006, 06:34 AM:name=Janus13)--][div class=\'quotetop\']QUOTE(Janus13 @ Mar 5 2006, 06:34 AM) [snapback]351766[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I've been trying to trace down a strange problem on some of my php pages where the page wouldn't carry variables from a sql query. The variables would end up being the logged on user's variables. My question, is once you set a variable in a page, does it clear when you leave that page or do you have to unset it?
[/quote]
Variables are only available on the page your set them on. If you want your variables to be available to you on the next page then you'll want to use sessions or transfer the data via the URL, but only if its not personal info being passed over the url. If it is then use sessions.

[!--quoteo(post=351766:date=Mar 5 2006, 06:34 AM:name=Janus13)--][div class=\'quotetop\']QUOTE(Janus13 @ Mar 5 2006, 06:34 AM) [snapback]351766[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Also, if I set a session variable of username, and then define a variable of $username, would those conflict?
[/quote]
From what you mentioned here I feel that you register_gloabls set to on which can be a big no no! As this can bring security issues to your site. When you srt register)globals to off you shouldn't get variable conflicts, as you use super global arrays to retrieve your session, post, get data use $_SESSION, $_POST or $_GET and many others.
Link to comment
https://forums.phpfreaks.com/topic/4128-php-variables-sticking/#findComment-14423
Share on other sites

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.