Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vanishing session - Session is lost when opening a new window ... 1

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
Working on a PHP application where I use session variables to track user credentials. I have added an additional module and for the sake of testing prior to deployment, I placed module one directory over (ie:
I am using an integrated routine to allow end-user the maintenance of a table (CRUD). The process is simple and I am using JavaScript onclick() event to execute JavaScript function which in turn open a new window calling the PHP script where the CRUD takes place.

The problem I am having is that when the PHP script is opened, the session is blank as if I has not been set. The same routine works just fine in the same server running off the root/webdocs directory (
Since the session is lost, PHP scripts routes user to log on prior to accessing the CRUD application, as it should.

Why am I loosing my session? No PHP script runs that would clear the session; I am going from onclick="openCRUD();" and openCRUD() opens a new window pointing to crud.php ...

Thank you all for you assistance!




--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
do you get the same behaviour in all browsers? and are you sure there is no second level subdomain (like www) on one of the links?
 
Same behavior on IE and FF. The image link
Code:
<img src="../gif/addressbook.gif" alt="" title="Consignee Address Book" onmouseover="this.style.cursor='pointer'; ShowHelp('11');" onmouseout="this.style.cursor='default'; UnTip()" onclick="cneeMaint();" />

The JS function
Code:
	function cneeMaint() {
		cneeWIN = window.open("cneeMaint.php","cneeWIN","location=1,status=0,scrollbar=1,width=900,height=600,scrollbars=1,resizable=1,menubar=0,location=0,status=0");
		cneeWIN.moveTo(0,0);
	}

The PHP redirect code
Code:
if ($_SESSION['username'] == '' || $_SESSION['client_name'] == '') { 
echo '
<html>
<head>
<script>
window.location="[URL unfurl="true"]https://mysite.com/";[/URL]
</script>
</head>
<body>
</body>
</html>
';

exit();
}

I have put echo commands just above the link to see what the variables are set to and right at the top of the cneeMaint.php script.

Everything session related is blank by the time cneeMaint.php is loaded, every session variable set upon valid logon to built-in session variables/arrays. I even tried checking the value of session_id() and it comes back blank as well.

It does not take much to confuse me but this one has really gotten to me. I bothers more so because I used this same code throughout this site and it just decided to break on me.



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
I'm sure you have thought of this and/or its probably in a segment of c ode you have not posted,, but since I don't see it in your code, I'll ask any way:

Do you have a session_start() call before you attempt to check the session variables?




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
No I do not!

I tried using it but it was starting a totally new session and the echoed session_id() was not same as that shown prior to calling cneeMaint.php script.



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
You need to cal session_start() in every page that is going to use the sessions. Otherwise sessions are not available.

If its starting a new sessions rather than resuming a previous one, it might not be finding the correct session_id for it. Likely caused by having JS redirect.

You may need to specify a session name or id before calling session_start();

Code:
session_name("mysessionname");
session_start();
...




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
vacunita, that fixed it ... I used your syntax on both index.php and cneeMaint.php and my CRUD works fine now.

I have never used this but I guess it now becomes a standard practice for me.

Thank you very much!

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top