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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sessions driving me demented

Status
Not open for further replies.

petermeachem

Programmer
Joined
Aug 26, 2000
Messages
2,270
Location
GB
This should be easy.
In login.php I've got
session_start();
echo $_POST['username'];
$HTTP_SESSION_VARS["username"] = $_POST['username'];

I used $HTTP_SESSION_VARS as none of the other methods I found worked. This seemed to work 1/2 an hour ago, but I now get a blank session file. The echo gives the correct value for username of admin.

 
Assuming you're in a recent version of PHP go ahead and switch to
Code:
$_SESSION['username']=$_POST['username'];

Other than that though... it's hard to say more with the rest of the code... here's a simple test though...
Code:
File1:
<?php
session_start();
$_SESSION['testval']='Foo';
echo '<a href="file2.php">Test the session</a>';
echo '<hr /><pre>';
print_r($_SESSION);
echo '</pre>';
?>

File2:
<?php
session_start();
echo '<pre>';
print_r($_SESSION);
?>

No easier way to see if you're sessions are functioning properly.
 
4.1.2

Are you sitting there day and night pressing F5? You always seem to answer within about a ms!

File 1 looks like
Test the session
--------------------------------------------------------------------------------

Array
(
[testval] => Foo
)

And file 2

Array
(
)


The session file is empty.

This isn't right is it?

 
login.php now contains

session_start();
session_register('username');
header( "Location: );

and the session file contains
username|s:5:"admin";

The top of BusinessCards.php contains

<?php
session_start();
if(session_is_registered('username')){
}
else{
header( "Location: );
}

Running this creates a second session file which is blank and the code pops back to login.htm (which calls login.php on Submit)



 
<aside>
I use Opera as my main web browser. One feature it has is to automatically reload a given page on an arbitrary schedule.
</aside>

I don't suppose you have an opportunity to upgrade, do you? There's lots of bugfixes and feature enhancements between what you're running and the current version.


With what web server are you running PHP? If it's IIS, there's a known issue (described as a feature by Microsoft) wherein IIS does not transmit cookies when you set the "Location:" header.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yeah, PWS is the source of your problem.

When you invoke session_start() in the first script, a session store is created on your drive and the cookie is set to be sent to the browser. The session value is stored. Then the "Location:" header prevents the session id cookie from being transmitted to the browser.

So when you run the next script and it invokes session_start(), PHP doesn't find a session id cookie so it creates a new id and session store and sets the new value in a cookie.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
There is a workaround: use of the "http-equiv" <meta> tag in your HTML output:

<META HTTP-EQUIV="Refresh" CONTENT=";URL=http://nt4work/php/BusinessCards.php">


You can also do the same thing with JavaScript.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top