This topic is locked
[SOLVED]

 $_SESSION in external page

10/26/2013 4:11:27 PM
PHPRunner General questions
bbarker author

Q: Are Session variables from PHPR pages available for use in EXTERNAL pages?
I have a $_SESSION variable that I save and use with PHPR reports. It works goodon those pages.

I set it in the Button Properties/Server tab:



$data = $button->getCurrentRecord();

$_SESSION['idregionrmr']=$data['idregion_rmr'];


But when I display a custom-reportthat I created and saved to the /SOURCEfolder, the variable doesn't work.
Here's the beginning and end of the query:



$result = mysql_query("Select ---- etc

WHERE t6.idregion_rmr = '".$_Session['idregionrmr']."'");


If I "Set" the $_SESSION at the top of the custom-report page, then it works.

$_SESSION['idregionrmr']=77;


Why doesn't my EXTERNAL page use the $_SESSION variable?

C
cgphp 10/26/2013

In the beginning of EXTERNAL pages, add the following line after the opening php tag:

session_start();
bbarker author 10/26/2013

Actually I have that on the page already... although it's about the 10th or 11th line - right after a bunch of // Remarks lines.
I'll move it higher and see if that changes anything.
-----UPDATE---------

Moved it just under <?PHP and it didn't change anything.

I have TWO Session Variables that I'm trying to use on the "external PHP" page... but neither of them show up.
Any other ideas? Is there any way to see the problem in Firebug?

Admin 10/27/2013

PHP session variables are available in all PHP files. As Cristian mentioned all you need to do is to include session_start() in the beginning of custom file.
Try to put something like this in the beginning of external PHP page:

session_start();

print_r($_SESSION);
bbarker author 10/27/2013



PHP session variables are available in all PHP files. As Cristian mentioned all you need to do is to include session_start() in the beginning of custom file.
Try to put something like this in the beginning of external PHP page:

session_start();

print_r($_SESSION);



I've tried that already... Just did it again and I get a page similar to this...


One other hint.. in order for the external page to work I have the following line in it....

$con=mysql_connect("127.0.0.1","userid","password","database");

with the appropriate values....
Is this somehow "overriding" the access to the session variables?

bbarker author 10/27/2013

Even simple echos don't show up....
echo $_Session['namergn'];
I browsed over 200 threads last night and completely READ about 50 of them. (Spent almost 5 hours.)
I saw about 12 of them that had the exact same issue... where an external page wasn't responding to $_SESSION variables.
There were no real good suggestions offered different than what we've already tried -- and most of all, no one ever posted what the final solution was that they used..... that's a shame.
I think that I'll rebuild a new external page with the absolute bare minimum number of lines and link it... let's see what that does.

Admin 10/28/2013

This might be incorrect syntax, $_SESSION (correct) vs $_Session (incorrect)
Instead of this:

echo $_Session['namergn'];


try this:

echo $_SESSION['namergn'];
bbarker author 10/28/2013

Yes!!! That was it. Good Monday morning present. Thanks Sergey.
FOR REFERENCE:
The following are NOT correct-

$_Session

$_session


This is correct:

$_SESSION
Admin 10/28/2013

As a rule of thumb - assume everything is case sensitive unless specified otherwise.