FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » session array not available in popup?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
session array not available in popup? [message #176984] Mon, 13 February 2012 19:21 Go to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
Hi There,

I have a session in my main window. Freom here, I want to open a
popup, load a page and access the $_SESSION[] array but I seem not
able to in my pop up.
<?php
session_start();
var_dump($_SESSION);
?>
at the top of my popup script just prints
array(0) { }
and this is what the session dumps on the page from where I open the
popup:
string(2) "10"

Why is that? What's going on here, I seems to recall that i used this
before and it worked just fine - any clues?

Thank you!
Ron
Re: session array not available in popup? [message #176985 is a reply to message #176984] Mon, 13 February 2012 19:30 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/13/2012 2:21 PM, cerr wrote:
> Hi There,
>
> I have a session in my main window. Freom here, I want to open a
> popup, load a page and access the $_SESSION[] array but I seem not
> able to in my pop up.
> <?php
> session_start();
> var_dump($_SESSION);
> ?>
> at the top of my popup script just prints
> array(0) { }
> and this is what the session dumps on the page from where I open the
> popup:
> string(2) "10"
>
> Why is that? What's going on here, I seems to recall that i used this
> before and it worked just fine - any clues?
>
> Thank you!
> Ron

Are you outputting ANYTHING - including whitespace - before the call to
session_start()?

Is the popup accessing the same domain as the main window?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: session array not available in popup? [message #176986 is a reply to message #176985] Mon, 13 February 2012 19:37 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Feb 13, 11:30 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 2/13/2012 2:21 PM, cerr wrote:
>
>
>
>
>
>
>
>
>
>> Hi There,
>
>> I have a session in my main window. Freom here, I want to open a
>> popup, load a page and access the $_SESSION[] array but I seem not
>> able to in my pop up.
>> <?php
>> session_start();
>> var_dump($_SESSION);
>> ?>
>> at the top of my popup script just prints
>> array(0) { }
>> and this is what the session dumps on the page from where I open the
>> popup:
>> string(2) "10"
>
>> Why is that? What's going on here, I seems to recall that i used this
>> before and it worked just fine - any clues?
>
>> Thank you!
>> Ron
>
> Are you outputting ANYTHING - including whitespace - before the call to
> session_start()?
No,

In both files, the first characters are:
<?php
session_start();

> Is the popup accessing the same domain as the main window?

Yes, they're both on the same domain, different directories tho but
that shouldn't matter, would it?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
Re: session array not available in popup? [message #176987 is a reply to message #176986] Mon, 13 February 2012 20:04 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Feb 13, 11:37 am, cerr <ron.egg...@gmail.com> wrote:
> On Feb 13, 11:30 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>
>
>
>
>
>
>> On 2/13/2012 2:21 PM, cerr wrote:
>
>>> Hi There,
>
>>> I have a session in my main window. Freom here, I want to open a
>>> popup, load a page and access the $_SESSION[] array but I seem not
>>> able to in my pop up.
>>> <?php
>>> session_start();
>>> var_dump($_SESSION);
>>> ?>
>>> at the top of my popup script just prints
>>> array(0) { }
>>> and this is what the session dumps on the page from where I open the
>>> popup:
>>> string(2) "10"
<?php
session_start();
echo session_id();

Now I tried passing the session id along as a get variable and in my
pop up script it now says
<?php
session_start();
echo $_GET['sessionid']."<br/>";
session_id($_GET['sessionid']);
echo session_id();
?>
On top. I confirm that the session id gets set to the correct value
but I still can't retrieve my UserID value from the session variable.
Something seems to be majorly messed up... :(
Re: session array not available in popup? [message #176988 is a reply to message #176986] Mon, 13 February 2012 20:12 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
cerr wrote:
> On Feb 13, 11:30 am, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 2/13/2012 2:21 PM, cerr wrote:

>>> <?php
>>> session_start();
>>> var_dump($_SESSION);
>>> ?>
>>> at the top of my popup script just prints
>>> array(0) { }
>>> and this is what the session dumps on the page from where I open the
>>> popup:
>>> string(2) "10"

If you have used

$_SESSION = "10";

then you haven't used the session as it's intended to work, try instead:

$_SESSION['integer'] = 10;


>> Is the popup accessing the same domain as the main window?
>
> Yes, they're both on the same domain, different directories tho but
> that shouldn't matter, would it?

Depends on your session.cookie_path

See: http://www.php.net/manual/en/function.session-set-cookie-params.php
http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-p ath

OT: Please remove things that you don't reply at, like signatures.


--

//Aho
Re: session array not available in popup? [message #176989 is a reply to message #176988] Mon, 13 February 2012 20:53 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Feb 13, 12:12 pm, "J.O. Aho" <u...@example.net> wrote:
> cerr wrote:
>> On Feb 13, 11:30 am, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>>> On 2/13/2012 2:21 PM, cerr wrote:
>>>> <?php
>>>> session_start();
>>>> var_dump($_SESSION);
>>>> ?>
>>>> at the top of my popup script just prints
>>>> array(0) { }
>>>> and this is what the session dumps on the page from where I open the
>>>> popup:
>>>> string(2) "10"
>
> If you have used
>
> $_SESSION = "10";

I didn't.

>
> then you haven't used the session as it's intended to work, try instead:
>
> $_SESSION['integer'] = 10;

I do use it like an array: $_SESSION['userid']
>
>>> Is the popup accessing the same domain as the main window?
>
>> Yes, they're both on the same domain, different directories tho but
>> that shouldn't matter, would it?
>
> Depends on your session.cookie_path
>
> See:http://www.php.net/manual/en/function.session-set-cookie-params.phphttp ://www.php.net/manual/en/session.configuration.php#ini.session.co...

I'm currently not using cookies, I'm passing the sessionid as a get
variable to the script and set it like:
session_id($_GET['sessionid']);
session_start();
echo $_GET['sessionid']."<br/>";
echo session_id();

>
> OT: Please remove things that you don't reply at, like signatures.

Yep, sorry
Re: session array not available in popup? [message #176990 is a reply to message #176989] Mon, 13 February 2012 22:15 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
cerr wrote:

> I'm currently not using cookies,

If you are using sessions, you are using cookies.

How else do you think they worked?
Re: session array not available in popup? [message #176991 is a reply to message #176990] Mon, 13 February 2012 23:45 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(The Natural Philosopher)

> cerr wrote:
>
>> I'm currently not using cookies,
>
> If you are using sessions, you are using cookies.

Not necessarily.

> How else do you think they worked?

Read what he wrote: SID in URL. Yes, it works, but is not recommended.

Micha

--
http://mfesser.de/blickwinkel
Re: session array not available in popup? [message #176992 is a reply to message #176989] Mon, 13 February 2012 23:59 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(cerr)

> I'm currently not using cookies, I'm passing the sessionid as a get
> variable to the script and set it like:

Then most likely the SID gets lost when you open your pop-up. In cases
like this you would have to manually append the predefined constant
'SID' to your URL. See the manual for details. [1]

But the better and recommended way would be to use a session cookie -
that's what cookies are for. SIDs in URLs are a security risk, because
they're stored in logfiles and in HTTP Referrer headers, which exposes
the SID to other people and might allow session hijacking. [2]

So better use a cookie instead, which is safer and should also solve
your problem. Also change these configuration options:

session.use_trans_sid = 0
session.use_only_cookies = 1

to prevent PHP from automatically rewriting URLs.

Micha

[1] http://www.php.net/manual/en/session.idpassing.php
[2] http://www.php.net/manual/en/session.security.php

--
http://mfesser.de/blickwinkel
Re: session array not available in popup? [message #176993 is a reply to message #176991] Tue, 14 February 2012 11:59 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Michael Fesser wrote:
> .oO(The Natural Philosopher)
>
>> cerr wrote:
>>
>>> I'm currently not using cookies,
>> If you are using sessions, you are using cookies.
>
> Not necessarily.
>
>> How else do you think they worked?
>
> Read what he wrote: SID in URL. Yes, it works, but is not recommended.
>

Ghastliness personified.


> Micha
>
Re: session array not available in popup? [message #176994 is a reply to message #176992] Tue, 14 February 2012 18:33 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Feb 13, 3:59 pm, Michael Fesser <neti...@gmx.de> wrote:
> .oO(cerr)
>
>> I'm currently not using cookies, I'm passing the sessionid as a get
>> variable to the script and set it like:
>
> Then most likely the SID gets lost when you open your pop-up. In cases
> like this you would have to manually append the predefined constant
> 'SID' to your URL. See the manual for details. [1]
>
> But the better and recommended way would be to use a session cookie -
> that's what cookies are for. SIDs in URLs are a security risk, because
> they're stored in logfiles and in HTTP Referrer headers, which exposes
> the SID to other people and might allow session hijacking. [2]
>
> So better use a cookie instead, which is safer and should also solve
> your problem. Also change these configuration options:
>
> session.use_trans_sid = 0
> session.use_only_cookies = 1
>
> to prevent PHP from automatically rewriting URLs.
>
> Micha
>
> [1]http://www.php.net/manual/en/session.idpassing.php
> [2]http://www.php.net/manual/en/session.security.php
>
> --http://mfesser.de/blickwinkel



So Thanks for everyone's feedback. I suddenly started to work as
expected which is very confusing to me and to me... I can not tell
what made this happen... I went as far as rebooting Windows, trying
different browsers and and and.... and then it suddenly... just
worked... :o Very strange and kinda scary!

Thanks for everyone's feedback anyways, it is much appreciated!

Ron
Re: session array not available in popup? [message #176995 is a reply to message #176993] Tue, 14 February 2012 18:30 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Feb 14, 3:59 am, The Natural Philosopher <t...@invalid.invalid>
wrote:
> Michael Fesser wrote:
>> .oO(The Natural Philosopher)
>
>>> cerr wrote:
>
>>>> I'm currently not using cookies,
>>> If you are using sessions, you are using cookies.
>
>> Not necessarily.
>
>>> How else do you think they worked?
>
>> Read what he wrote: SID in URL. Yes, it works, but is not recommended.
>
> Ghastliness personified.

Yep, I read up on it, I'm using them with cookies.
Re: session array not available in popup? [message #177005 is a reply to message #176984] Wed, 15 February 2012 17:34 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 13/02/2012 20:21, cerr escribió/wrote:
> I have a session in my main window. Freom here, I want to open a
> popup, load a page and access the $_SESSION[] array but I seem not
> able to in my pop up.
> <?php
> session_start();
> var_dump($_SESSION);
> ?>
> at the top of my popup script just prints
> array(0) { }
> and this is what the session dumps on the page from where I open the
> popup:
> string(2) "10"
>
> Why is that? What's going on here, I seems to recall that i used this
> before and it worked just fine - any clues?

$_SESSION is an array, not a string, so the funny thing is that it's
only working as expected in the popup window :)


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Space mistery
Next Topic: PHP 5.3.9 hex bug?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 01:51:54 GMT 2024

Total time taken to generate the page: 0.02718 seconds