RE: [PHP] Session confusion again :( - Thanks!

2004-04-15 Thread Ford, Mike [LSS]
On 14 April 2004 17:53, Paul Fine wrote:

 Thanks guys but I have register globals ON so once the
 session variable is
 defined I should be able to address it without specifying $_SESSION ?

I don't think the documentation is clear on this point -- it may be that the
association between the global variable and the $_SESSION array doesn't
take until the next page load and session_start(), and in any case the
behaviour seems to be different between 4.2 and 4.3.  I *think* you may have
to session_register('element_countp') to make the association in the current
page, but this is buggy and seriously disrecommended in 4.2 (although fixed
in 4.3).

Personally, I'd just use the $_SESSION[] variable anyway, and not bother
with the equivalent global.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Session confusion again :( - Thanks!

2004-04-15 Thread Richard Harb
Actually for me it isn't unclear at all:

The (super-) global variables are created when php starts working on
your script.

That pesky function/ini parameter (register_globals=on) is just a
replacement for an extract() on each of the global vars just then.

Whatever you do later with any of the variables is up to you - that
extract won't 'run' again - even with register_globals on

Similar to this: if you change some $_POST or $_GET var 'manually' the
$_REQUEST doesn't get updated ...

Richard


Thursday, April 15, 2004, 1:35:19 PM, you wrote:

 On 14 April 2004 17:53, Paul Fine wrote:

 Thanks guys but I have register globals ON so once the
 session variable is
 defined I should be able to address it without specifying $_SESSION ?

 I don't think the documentation is clear on this point -- it may be that the
 association between the global variable and the $_SESSION array doesn't
 take until the next page load and session_start(), and in any case the
 behaviour seems to be different between 4.2 and 4.3.  I *think* you may have
 to session_register('element_countp') to make the association in the current
 page, but this is buggy and seriously disrecommended in 4.2 (although fixed
 in 4.3).

 Personally, I'd just use the $_SESSION[] variable anyway, and not bother
 with the equivalent global.

 Cheers!

 Mike

 -
 Mike Ford,  Electronic Information Services Adviser,
 Learning Support Services, Learning  Information Services,
 JG125, James Graham Building, Leeds Metropolitan University,
 Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
 Email: [EMAIL PROTECTED]
 Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Session confusion again :( - Thanks!

2004-04-14 Thread Chris W. Parker
BOOT mailto:[EMAIL PROTECTED]
on Wednesday, April 14, 2004 9:40 AM said:

 What I can't understand is why Test1 shows as nothing, while
 Test2 shows the value I wanted. Thanks a lot!

[snip]

 $_SESSION['element_countp'] = count($p_lnames);
 echo TEST 1.$element_countp;
 
 $element_countp = $_SESSION['element_countp'];
 echo TEST 2.$element_countp;

because in test 1 $element_countp has not been assigned anything yet.

$_SESSION['element_countp'] and $element_countp are *not* the same
variable (it appears that you think they are).

in test 2 you assign the value of $_SESSION['element_countp'] to
$element_countp so that's why test 2 works.


hth,
chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Session confusion again :( - Thanks!

2004-04-14 Thread Ford, Mike [LSS]
On 14 April 2004 17:40, BOOT wrote:

 Any help with this would be appreciated. the p and v lnames are
 posted from a form. In the form, the user seperates last names with a
 /. What I can't understand is why Test1 shows as nothing, while
 Test2 shows the value I wanted. Thanks a lot!
 
 
 $p_lnames= explode(/, $p_lnames);
 
 
 $_SESSION['element_countp'] = count($p_lnames);
 
 
 echo TEST 1.$element_countp;

Because here, you haven't assigned anything to $element_countp -- you've
only assigned it to $_SESSION['element_countp'].  (With register_globals
Off, the two are not the same.)  If you turned your error_reporting level up
to E_ALL, you'd probably get a warning at this point saying that
$element_countp is undefined.

 
 
 $element_countp = $_SESSION['element_countp'];
 
 
 echo TEST 2.$element_countp;

Now you've assigned a value to $register_countp, so you get it output.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Session confusion again :( - Thanks!

2004-04-14 Thread Paul Fine
Thanks guys but I have register globals ON so once the session variable is
defined I should be able to address it without specifying $_SESSION ?

-Original Message-
From: Chris W. Parker [mailto:[EMAIL PROTECTED] 
Sent: April 14, 2004 11:48 AM
To: BOOT; [EMAIL PROTECTED]
Subject: RE: [PHP] Session confusion again :( - Thanks!

BOOT mailto:[EMAIL PROTECTED]
on Wednesday, April 14, 2004 9:40 AM said:

 What I can't understand is why Test1 shows as nothing, while
 Test2 shows the value I wanted. Thanks a lot!

[snip]

 $_SESSION['element_countp'] = count($p_lnames);
 echo TEST 1.$element_countp;
 
 $element_countp = $_SESSION['element_countp'];
 echo TEST 2.$element_countp;

because in test 1 $element_countp has not been assigned anything yet.

$_SESSION['element_countp'] and $element_countp are *not* the same
variable (it appears that you think they are).

in test 2 you assign the value of $_SESSION['element_countp'] to
$element_countp so that's why test 2 works.


hth,
chris.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Session confusion again :( - Thanks!

2004-04-14 Thread Dennis Gearon
'Chris W. Parker' [EMAIL PROTECTED] elucidated:

Thanks guys but I have register globals ON so once the session variable is
defined I should be able to address it without specifying $_SESSION ?


WHERE do you have it on? Most sites now have it turned off for VERY valid security reasons. If you are turning it on in your prepend file - Sorry, too late.

The only two places to turn it back on, to my knowledge, is in your ini file for the site, or your .htaccess file as a directive. Only those two places are before the GPC processing.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Session confusion again :( - Thanks!

2004-04-14 Thread BOOT
Yes in php.ini. I never bothered turning off as (a) I did not take the time
to understand the implications and (b) my project is only for internal
network use anyway.

So I went and turned them off. Now of course my pages don't work properly. I
guess I have to go through all my code and address the variables properly
ie. $_POST and $_SESSION?

Thanks!



Dennis Gearon [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 'Chris W. Parker' [EMAIL PROTECTED] elucidated:

 Thanks guys but I have register globals ON so once the session variable
is
 defined I should be able to address it without specifying $_SESSION ?


 WHERE do you have it on? Most sites now have it turned off for VERY valid
security reasons. If you are turning it on in your prepend file - Sorry, too
late.

 The only two places to turn it back on, to my knowledge, is in your ini
file for the site, or your .htaccess file as a directive. Only those two
places are before the GPC processing.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Session confusion again :( - Thanks!

2004-04-14 Thread Chris W. Parker
BOOT mailto:[EMAIL PROTECTED]
on Wednesday, April 14, 2004 12:17 PM said:

 So I went and turned them off. Now of course my pages don't work
 properly. I guess I have to go through all my code and address the
 variables properly ie. $_POST and $_SESSION?

no.

just assign them at the beginning of your file.

CURRENT FILE:
?php

echo $username is logged in!!;
echo hello $username, you are logged in.;

?

WHAT I THINK YOU WOULD CHANGE IT TO:
?php

echo {$_GET['username']} is logged in!!;
echo hello {$_GET['username']}, you are logged in.;

?

WHAT YOU SHOULD DO INSTEAD:
?php

$username = $_GET['username'];

echo $username is logged in!!;
echo hello $username, you are logged in.;

?

of course. don't forget to validate your incoming data.


hth,
chris.  

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Session confusion again :( - Thanks!

2004-04-14 Thread BOOT
But if I want to use $username accross many pages then I will have to make
it a session variable and call it as such on each page like
$_SESSION['username']

Thanks again!



Chris W. Parker [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
BOOT mailto:[EMAIL PROTECTED]
on Wednesday, April 14, 2004 12:17 PM said:

 So I went and turned them off. Now of course my pages don't work
 properly. I guess I have to go through all my code and address the
 variables properly ie. $_POST and $_SESSION?

no.

just assign them at the beginning of your file.

CURRENT FILE:
?php

echo $username is logged in!!;
echo hello $username, you are logged in.;

?

WHAT I THINK YOU WOULD CHANGE IT TO:
?php

echo {$_GET['username']} is logged in!!;
echo hello {$_GET['username']}, you are logged in.;

?

WHAT YOU SHOULD DO INSTEAD:
?php

$username = $_GET['username'];

echo $username is logged in!!;
echo hello $username, you are logged in.;

?

of course. don't forget to validate your incoming data.


hth,
chris.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Session confusion again :( - Thanks!

2004-04-14 Thread Chris W. Parker
BOOT mailto:[EMAIL PROTECTED]
on Wednesday, April 14, 2004 12:37 PM said:

 But if I want to use $username accross many pages then I will have to
 make it a session variable and call it as such on each page like
 $_SESSION['username']

correct.



c.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php