f



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.

0
4/12/2005 9:12:58 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

2 Replies
438 Views

Similar Articles

[PageSpeed] 17

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
0
4/12/2005 10:24:59 AM
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

0
m.ramius (17)
4/13/2005 5:30:25 PM
Reply:

Similar Artilces:

Assigning a php variable to a jquery variable?
Hi, How to assign a php variable in a jquery variable . can anyone help me out.Thanks . Regards Venkat venky_lb wrote: > Hi, > How to assign a php variable in a jquery variable . can anyone help > me out.Thanks . Why would you want to? Jquery is absolute junk. In any case there is no such thing as a "jquery variable". There just might however be a javascript variable involved. If you want to cause a javascript variable to have the same value as your PHP variable (when the output from your PHP script eventually reaches the client) then: echo "<script type='text/javascript'>var js_variable='{php_variable}';</script>\r\n"; However, keep in mind that PHP runs on the server and javascript runs on the client and there is no interaction between them at all, other than client->server requests, that is: client requests a new page or runs some AJAX. -- Richard. rf escribi�: > venky_lb wrote: >> How to assign a php variable in a jquery variable . can anyone help >> me out.Thanks . > > Why would you want to? Jquery is absolute junk. Er... Why? > However, keep in mind that PHP runs on the server and javascript runs on the > client and there is no interaction between them at all Absolutely. This is the key point. > other than client->server requests, that is: client requests a new page or runs some > AJAX. There's no interaction either, beyond JavaScrip...

Assignment to a variable variable
Sometimes I want to assign a value to a variable whose name is a parameter. For example =E2=88=87 GetVar varname [1] slot=E2=86=90DIR=E2=8D=B3varname [2] =E2=8D=8Evarname,'=E2=86=90=E2=8E=95FREAD 1 slot' =E2=88=87 Line [2] is unpleasant, as execute often is. The awkward part is that the language forces me to execute a whole statement -- to artificially construct a character version of some code -- including the assignment arrow. Here's a proposed language enhancement that seems natural to me: (=E2=8D=8Evarname)=E2=86=90=E2=8E=95FREAD 1 slot Pro...

setting local variable also sets SESSION variable with same name
This is troubling: echo "SESSION user is: " . $_SESSION['user']; if (isset($_GET['user'])) { // firstpass $user = $_GET['user']; $name = fGetRealName($user); echo "<br /> firstpass, SESSION user is now: " . $_SESSION['user']; results in: SESSION user is: wpd firstpass, SESSION user is now: test It appears that assigning to $user is also setting $_SESSION['user'] ------------ php 5.2.3 Any ideas why this is happening ? bill bill schreef: > This is troubling: > > echo "SESSION user is: " . $_SESSION['user']; > > if (isset($_GET['user'])) { // firstpass > $user = $_GET['user']; > $name = fGetRealName($user); > echo "<br /> firstpass, SESSION user is now: " . $_SESSION['user']; > > results in: > SESSION user is: wpd > firstpass, SESSION user is now: test > > It appears that assigning to $user is also setting > $_SESSION['user'] > > ------------ > php 5.2.3 > > Any ideas why this is happening ? > > bill > Hi Bill, I bet you have register_globals set to on. What does the following give you? echo ini_get("register_globals"); (Or check your php.ini, look for register_globals.) In case it is On, put it to Off and never try to put it on again. ;-) This might break some old poorly written scripts on the same server too if they rely on register ...

Assign variables to a new variable based on variable names in SAS
Thank so much Nagakumar Sridhar and Fehd, Ronald J. for answering my previous question. However I was not clear in the original post. I modified my phrasing and the new version is below: I have met the following problem and I need your expert help. The variable names in the data set looks like this: a_1995q3 a_1995q4 a_1997q1 ........... a_2003q4 n Please note that "quarter" numbers in "a_****q*" variables may not be continuous, i.e. there might be a missing quarter. and n can have the value of any quarter for while a_quarter exists, say "1995q3", "...

variables with variable assigned names
Hi all I'm trying to assign a value to variable that changes its name according to the value of another variable. I've tried with this idea: structGroupnamef=genvarname(structGroupname); eval([structGroupnamef '=dbGroup.(structGroupname)']) but the problem is it sends the variable to the workspace, but i don't know how to get hold of it from my program. Regards & thanks Ana Hi, I think you can do it with global Variables. In your case the code global structGroupnamef; structGroupnamef=genvarname(structGroupname); eval([structGroupnamef '=dbGroup.(structGroup...

Re: Assign variables to a new variable based on variable names in SAS #7
Chang, I agree with your assessment of Richard's code. I especially liked that he offered it without any chest pounding! Joe -----Original Message----- From: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM> Sent: Jan 16, 2004 11:19 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Assign variables to a new variable based on variable names in SAS Hi, Richard, Your data step, "monkeyshines" is one of the prettest I have ever seen. Really nice. The to-the-point array statement using the variable name wild character (":"); use of lbound() hbound() f...

Re: Assign variables to a new variable based on variable names in SAS #6
Hi, Richard, Your data step, "monkeyshines" is one of the prettest I have ever seen. Really nice. The to-the-point array statement using the variable name wild character (":"); use of lbound() hbound() functions; use of _i_ for index variable; short but intuitive variable and array names like aVars, aBase, and aMap; use of intnx and intck functions, reading the returned variable name with ??yyq6. format, anticipation of range checking, and all the work was done in essentially a single line!("a_new = aVars[aMap[qtrIndex]];") ... I learn a lot just by reading your...

Re: Assign variables to a new variable based on variable names in SAS #3
Here's a solution that builds a list of subscripts in macro variables named like the 'a_' columns in the input dataset. 'a_' fields are referenced by the subscript from the array they're defined to be part of: data stuff; a_2003q4 = 44; a_2003q1 = 11; a_2003q2 = 22; a_2003q3 = 33; n = 'a_2003q3'; run; proc sql noprint; create table columns as select name from sashelp.vcolumn where libname = 'WORK' and memname = 'STUFF' and name eqt 'a_' order by name ; select compbl('...

Re: Assign variables to a new variable based on variable names in SAS #5
Hi Chang & V - I'm confused as usual - did you mean this? 142 data one; 143 a_1995q3 = 1; 144 a_1995q4 = 2; 145 a_1997q1 = 3; 146 a_2003q4 = 5; 147 n = "2003q4"; 148 run; NOTE: The data set WORK.ONE has 1 observations and 5 variables. NOTE: DATA statement used: real time 0.01 seconds cpu time 0.01 seconds 149 150 data two; 151 set one; 152 call symput('n', n); 153 new_a = 'a_'||resolve(n); 154 put new_a=; 155 run; new_a=a_2003q4 NOTE: There were 1 observations read from the data set WORK.ONE...

Re: Assign variables to a new variable based on variable names in SAS #4
On Thu, 15 Jan 2004 11:02:05 -0800, W M <mwx74@HOTMAIL.COM> wrote: >I have met the following problem and I need your expert help. >The variable names in the data set looks like this: > >a_1995q3 a_1995q4 a_1997q1 ........... a_2003q4 n > Is there a way like > >new_a=a_{value of n} ? > >Because of the compilation of data step, you cannot do > >data new; set old; >call symput("name", n); >new_a=a_&n; (wrong !) >run; Hi, V, Following up on Paul (Choate)'s idea, this seems to work. This would serve as an example of putting an...

assigning the variable value to the variable name
Hello, I am reading from an excel sheet (with the command xlsread), 2 columns. One column includes the variable name, the other one contains the varible value. the variable name is read as a string, the variable value is a number. Now I would like to assign the variable value to the variable name. How can I do this.? Thanks for the suggestions and the help. Best Regards, Ata "Ata " <ata.douzdouzani@ch.abb.com> wrote in message <i26f9r$7kp$1@fred.mathworks.com>... > Hello, > I am reading from an excel sheet (with the command xlsread), 2 columns. One colu...

assigning a macro variable value to a variable
I have a macro variable ' j ' that will range from 2 to 13, I try to assign it to a variable within a loop ( within a nested loop, several in fact) but all values for each variable are the same for the 13 observations created in the loop. By using the option symbolgen I know that the value of ' j ' changes at the point I try to assign it to a value for each observation. So I would expect the values of the variable to be different. This is how I'm currently trying to assign the value of the macro variable to a variable that is not a macro variable: JNUM = &j ; Than...

assigning column variable to macro variable
Hi, I want to know if there is a way to make a column variable a global variable. The following doesn't work data _null_; set test; %global var1; %let var1=variableOne; run; This makes var1 resolve to the text variableOne, rather than the value in column variableOne. Any suggestions? Thanks Check out the syntax for CALL SYMPUT. This is one way to assign macro variables in the data step. Jack Clark Research Analyst Center for Health Program Development and Management University of Maryland, Baltimore County -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of karma Sent: Thursday, December 20, 2007 8:36 AM To: SAS-L@LISTSERV.UGA.EDU Subject: assigning column variable to macro variable Hi, I want to know if there is a way to make a column variable a global variable. The following doesn't work data _null_; set test; %global var1; %let var1=variableOne; run; This makes var1 resolve to the text variableOne, rather than the value in column variableOne. Any suggestions? Thanks On Dec 20, 2:35 pm, karma <dorjeta...@googlemail.com> wrote: > Hi, > > I want to know if there is a way to make a column variable a global > variable. > > The following doesn't work > > data _null_; > set test; > %global var1; > %let var1=variableOne; > run; > > This makes var1 resolve to the text variableOne, rather than the value > in column ...

How To Dim a Variable When Assigning a Recordset to the Variable
I'm trying to loop through a recordset and add the field name and field value to a dictionary object. However, when I turn on Option Explicit, the line marked with an arrow gives me an "Invalid Use Of Property" error. I thought I declared rsFIELDS correctly, but apparently not... Any ideas as to how to correct this? Thanks! Tyler Private Sub cmdRun_Click() Dim IDFile, DemoFile, errorReturn As String Dim CnvRegQ As String Dim ProgBarCount, REGID2003, REGID2004 As Integer Dim rsFIELDS As ADODB.Recordset Def2003DSN = txt2003DSN.Text ...

assign a struct variable into another struct variable
Hi, I would appreciate if someone could tell me what I'm doing wrong ? #include<iostream> using namepace std ; struct person{ char *firstname ; int age ; } ; struct person1{ char *firstname ; int age ; } ; int main(int argc, char *argv[]) { person me ; person1 me1 ; me.firstname = "me" ; me.age = 150 ; me1 = me ; // here's where the problem occurrs..... *The Error Report I Get* (structs.cpp: in function 'int main()': structs.cpp:22: error: no match for 'operator=' in 'me1 = me' structs.c...

Assign a new variable the label from an existing variable
Hello, =20 I'm hoping to get suggestions from the list on the best way to assign a new variable the label from an existing variable. I am using SAS v8 on UNIX, but got similar error messages with V9.2 on Windows. =20 I have a dataset of coded variables. For example, I have a variable called COUNTY which is the 2-digit county code. The variable has a label - "County". I need to create a new variable (COUNTY_D) which is the formatted version of county, but I want it to have the same label as the coded variable COUNTY. =20 I was hoping that the VLABEL function could help, but either I am not using it properly or it is not allowed in this context. Any suggestions are appreciated. =20 =20 Data need; Set have; County_d =3D put(county,$county.); Attrib county_d label =3D vlabel(county); Run; =20 From the log: 6 county_d =3D put(county,$county.); 7 attrib county_d label =3D vlabel(county); - 22 76 ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, FORMAT, INFORMAT, LABEL, LABLE, LENGTH, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_. =20 ERROR 76-322: Syntax error, statement will be ignored. =20 =20 =20 Jack Clark Research Analyst Center for Health Program Development and Management University of Maryland, Baltimore County =20 You can copy attributes with an non-executed set. d...

Assign variables to a new variable dynamically in SAS
Dear all, I have met the following problem and I need your expert help. The variable names in the data set looks like this: a1 a3 a7 ........... a20 n Now I want to do this: if n=1 then new_a=a1; if n=2 then new_a=a2; ..... if n=20 then new_a=a20; Is there a simpler way using macro to do this in SAS ? Because I have several other variable sets to do, say b, c, d, .... Many thanks, V. On 15 Jan 2004 08:40:43 -0800, mwx74@hotmail.com (W M) wrote: >Dear all, > >I have met the following problem and I need your expert help. >The variable names in the data set looks like thi...

assigning the variable value to the variable name #2
Hello, I am reading from an excel sheet (with the command xlsread), 2 columns. One column includes the variable name, the other one contains the varible value. the variable name is read as a string, the variable value is a number. Now I would like to assign the variable value to the variable name. How can I do this.? Thanks for the suggestions and the help. Best Regards, Ata "Ata " <ata.douzdouzani@ch.abb.com> wrote in message <i26fdv$fnr$1@fred.mathworks.com>... > Hello, > I am reading from an excel sheet (with the command xlsread), 2 columns. One colu...

ndefined function or variable 'y'. The first assignment to a local variable determines its class. Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: "y"
Hi everybody I have a serious problem and i need your help. i use embedded matlab function in simulink to generate some matrices which i use as input to other bloc on simulink. But i got this error while the simulation is running: Undefined function or variable 'y'. The first assignment to a local variable determines its class. Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: "y" My code is function y = fcn(u) Ap=[0.9580 0 0 0;0 0.9418 0 0;0 0 0.9048 0;0 0 0 0.9277]; Bp=[0.25 0;0.25 0;0 0.5;0 0.5]; Cp=[0.1678 0 0.9516 0;0 0.2329 0 0.2890]; [m1,n1]=size(Cp); [n1,n_in]=size(Bp); A_e=eye(n1+m1,n1+m1); A_e(1:n1,1:n1)=Ap; A_e(n1+1:n1+m1,1:n1)=Cp*Ap; B_e=zeros(n1+m1,n_in); B_e(1:n1,:)=Bp; B_e(n1+1:n1+m1,:)=Cp*Bp; C_e=zeros(m1,n1+m1); C_e(:,n1+1:n1+m1)=eye(m1,m1); y(1:m1,:)=C_e; for kk=1:u-1; y((m1*kk)+1:m1*(kk+1),:)=y(m1*(kk-1)+1:m1*kk,:)*A_e; end thank you so much On 07/16/2014 5:50 AM, AGUEMON wrote: .... .... > ...i got this error while the simulation is > running: > > Undefined function or variable 'y'. The first assignment to a local > variable determines its class. > Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: > "y" > .... > C_e(:,n1+1:n1+m1)=eye(m1,m1); > y(1:m1,:)=C_e; > > for kk=1:u-1; > y((m1*kk)+1:m1*(kk+1),:)=y(m1*(kk-1)+1:m1*kk,:)*A_e; .... Never used the em...

confusion with local variable assignment
When you write a = b # error. As b is not defined as a method or local variable But if you try - a = a or b = b, MRI parse it without error. How the `a` or `b` on the right side is allowed, where as I didn't define them earlier. Thanks On 11.04.2014 15:24, Arup Rakshit wrote: > When you write > > a = b # error. As b is not defined as a method or local variable > > But if you try - > > a = a or b = b, MRI parse it without error. How the `a` or `b` on the > right side is allowed, where as I didn't define them earlier. There was recently a...

Assigning Bind Variables to Substitution Variables in PL/SQL
Hello all, I seem to be hitting an issue trying to assign a bind variable to substitution variable in PL/SQL block - no problem in plain old SQL*Plus. Here it is: --------------- using PL/SQL (does not work) --------------- i also tried without execute immediate - just by selecting into -did not help! Connected to: Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production With the Partitioning, OLAP and Oracle Data Mining options JServer Release 9.2.0.6.0 - Production SQL> column mydbid new_value dbid SQL> declare 2 x number; 3 begin 4 execute immediate 'select dbid mydbid from v$database' into x; 5 end; 6 / PL/SQL procedure successfully completed. SQL> define dbid SP2-0135: symbol dbid is UNDEFINED ----------- now using SQL - works like a charm! SQL> select dbid mydbid from v$database; MYDBID ---------- 1396901698 SQL> define dbid DEFINE DBID = 1396901698 (NUMBER) Any help in how to achieve this in PL/SQL is much appreicated! thanks -- suvinay On 2005-11-04, suvinay@gmail.com <suvinay@gmail.com> wrote: > Hello all, > I seem to be hitting an issue trying to assign a bind variable to > substitution variable in PL/SQL block - no problem in plain old > SQL*Plus. Here it is: > > > --------------- using PL/SQL (does not work) > --------------- i also tried without execute immediate - just by > selecting into -did not...

Assigning a field variable in awk program to a shell variable
hi myself a newbie to unix shell scripting and stuff.. i want to assign a field variable in an awk program to a shell variable. like for eg if shell_var is one of a shell variable then i want to assign the line numbers returned by the grep command with -n option to a shell variable. the code that i've tried is this grep -n string filename | awk -F : '{shell_var = $1}' it doesn't work please help.. deeplights@gmail.com wrote: > hi > myself a newbie to unix shell scripting and stuff.. > i want to assign a field variable in an awk program to a shell > variable. &g...

assign data to variable in sequence? like Variable(n)
Dear all, I am trying to assign data value to variable names in sequence . I have ten data and i wanna assign them each as Variable(n) where n is from 1 to 10. The data type is basically a read-in frame from video, so it has a 4D Uint8 type like Image(:,:,:,5) <= as in 5th frame I want to treat each frame as a separate Image, like assigning the 5th frame as varible called Variable(5). So i can easily call out Variable(n) whenever i want during a For Loop. how can i do that? Any help would be appreciated. Thank you in advance. In article <ef58e91.-1@webcrossing.raydaftYaTP>, Marc...

Assign variable to variable ? Why doesn't this work?
I'm using bash. Specifically, the last echo returns nothing. What am I missing? If I do this manually (assign variable to another variable) it works. ps -ef |grep -i searchtext|grep -i $remote |while read a b c d e f g h i j do echo $b $j pid=$b remotename=$j done echo $pid $remotename BTW, $remote is previously assigned in the script, but I didn't include it. On Tue, 27 Jan 2004 11:34:49 -0500, Mark <me@privacy.net> wrote: >I'm using bash. Specifically, the last echo returns nothing. What am I >missing? If I do this manually (assign variab...

Web resources about - What? Assigning a session variable also assigns the local variable? - comp.lang.php

South Carolina Legislators Vote to Cut University Funding for Assigning LGBT Books
Republican legislators in South Carolina want to teach two state universities a lesson for assigning books with LGBT themes.

Pitfall of Scrum: Assigning Tasks
Learn more about our Scrum and Agile training sessions on WorldMindware.com Even though the concept of self-organizing teams has been around ...

Google celebrates Teacher Appreciation Week by assigning new features to Classroom
The first full week of May is designated in the U.S. as Teacher Appreciation Week. It happens to be this week. And in honor of the occasion, ...

Assigning Odds to Every Potential Buccaneers 1st-Round Pick
The NFL draft is the most elaborate gambling enterprise in existence. Obviously, there is considerable skill involved in developing an NFL prospect, ...

Assigning Fault For Impending Democratic Congressional Losses
Last night we took a look at some of the poor schlubbs Steve Israel had recruited to run for Congress and has now abandoned, tainted by his losing ...

Assigning blame for new, more costly medical plan, Corporate points to Washington's favorite piñata
I'm always skeptical when companies make broad statements without citing dollar amounts or other hard numbers to back them up. That's why Corporate's ...

Programatically assigning a Customer Group in Magento
Magento’s Customer Groups give you the ability to offer different pricing and promotions to customers based upon their grouping. This grouping ...

Selfie With Parents’ Sex Toys? Alameda Teacher Accused Of Assigning Bizarre Extra Credit For Sophomores ...
Parents of students at an Alameda high school want a teacher fired after they say he sent them home with an extra credit assignment of finding ...


RG3 confirms progress, avoids assigning blame
In an exclusive interview with Redskins Nation, RG3 discusses his recovery and his desire to move past assigning blame.

Resources last updated: 3/24/2016 1:55:58 AM