472,794 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

What? Assigning a session variable also assigns the local variable?

Alright, what the hell is going on here?

In the following code, I expect the printed result to be:
DEBUG: frank's last name is burns.

Instead, what I get is:
DEBUG: frank's last name is burns.

Here is the code:
$frank = "burns";
$_SESSION['frank'] = "black";
echo "DEBUG: frank's last name is is $frank";

What is coming into play here? I thought of register_globals but I
thought that only dealt with GET, POST, REQUEST, etc.

Jul 17 '05 #1
2 2980
thecrow wrote:
Alright, what the hell is going on here?

In the following code, I expect the printed result to be:
DEBUG: frank's last name is burns.

Instead, what I get is:
DEBUG: frank's last name is burns.
That is than excactly what you wanted. :P

Here is the code:
$frank = "burns";
$_SESSION['frank'] = "black";
echo "DEBUG: frank's last name is is $frank";
So what is your problem?
$frank contains "burns", so what else should PHP print?

If you want the content for the session-var 'frank', use it.
Like:
echo "DEBUG: frank's last name is is ".$_SESSION['frank'];

What is coming into play here? I thought of register_globals but I
thought that only dealt with GET, POST, REQUEST, etc.


Indeed.

Go get a cup of coffee.
You are just being sloppy. :-)

Regards,
Erwin Moller
Jul 17 '05 #2
Erwin Moller wrote:
thecrow wrote:
Alright, what the hell is going on here?

In the following code, I expect the printed result to be:
DEBUG: frank's last name is burns.

Instead, what I get is:
DEBUG: frank's last name is burns.


That is than excactly what you wanted. :P

Here is the code:
$frank = "burns";
$_SESSION['frank'] = "black";
echo "DEBUG: frank's last name is is $frank";


So what is your problem?
$frank contains "burns", so what else should PHP print?

If you want the content for the session-var 'frank', use it.
Like:
echo "DEBUG: frank's last name is is ".$_SESSION['frank'];

What is coming into play here? I thought of register_globals but I
thought that only dealt with GET, POST, REQUEST, etc.


Indeed.

Go get a cup of coffee.
You are just being sloppy. :-)

Regards,
Erwin Moller


I think thecrow meant to say:
In the following code, I expect the printed result to be:
DEBUG: frank's last name is burns.

Instead, what I get is:
DEBUG: frank's last name is black.

Here is the code:
session_start();
$frank = "burns";
$_SESSION['frank'] = "black";
echo "DEBUG: frank's last name is is $frank";

I tried this test with register_globals turned on and turned off. With
it on, I got what thecrow got. With it off, I got what thecrow had
hoped for. So yes, register_globals is the culprit.

It makes sense for $_SESSION to trump other variables when
register_globals is turned on. Imagine if a malicious user passed
"user_level=admin" on the query string. And in that PHP page, you
populated $_SESSION['user_level'] with the result of a database query.
What would you like to see when accessing $user_level? The data you
explicitly put into $_SESSION or the data the malicious user passed to
your script?

It is because of the confusing and possibly dangerous side-effects of
register_globals that it was disabled by default as of PHP 4.2.0

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeff | last post by:
I've searched the web for hours trying to figure out this problem and can't seem to find any pertinent answers. I have a website where the user starts on a login page, puts in their credentials and...
0
by: toedipper | last post by:
Hello, windows xp, apache, php and my sql and dreamweaver mx I have the code below. And it does'nt work! Basically the code below is the workings behind the scene that inserts a record to a...
0
by: Eyal Lotem | last post by:
Python has a few issues many consider problems with regard to its variable namespacing. It seems that the local/global/builtins namespacing rules are ancient remnants of a different Python. ...
8
by: Tammy B. | last post by:
Hiya - Big puzzler for me. Code Below I create a class. I save it to a session variable. Then, I retrieve the session variable back into a new local variable. I am able to use a method which...
5
by: F. Da Costa | last post by:
Hi, Could it be correct that the following code does *not* work because i'm not using the var arr = new Array("a","b","c"); methodology?? Read through...
7
by: Nicole | last post by:
Hi I'm trying to use a function to set a session variable. I have three files: The first file has: <?php session_start(); // This connects to the existing session ?> <html> <head>
38
by: Zytan | last post by:
What is the difference between these two lines? Dim args As Object() = New Object() {strText} Dim args As Object() = {strText} args seems usuable from either, say, like so: ...
18
by: Xah Lee | last post by:
What are OOP's Jargons and Complexities Xah Lee, 20050128 Classes, Methods, Objects In computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) {...
5
by: Vols | last post by:
class A{ public: int x; }; class B : public A{ public: int y; }; void foo()
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.