Jump to content


Photo

PHP Variables sticking


  • Please log in to reply
2 replies to this topic

#1 Janus13

Janus13
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 05 March 2006 - 06:34 AM

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?

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 05 March 2006 - 11:24 AM

It sounds like you might have register_globals switched on in your php.ini file. It should be switched off, at least for security reasons.

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 March 2006 - 06:14 PM

[!--quoteo(post=351766:date=Mar 5 2006, 06:34 AM:name=Janus13)--][div class=\'quotetop\']QUOTE(Janus13 @ Mar 5 2006, 06:34 AM) View Post[/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) View Post[/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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users