Jump to content

[SOLVED] Sessions Running but not Functioning - Background Program Blocking?


kingtheoden

Recommended Posts

Running Apache 2.2 and PHP 5.2 on XP Professional, when I check my PHP info page, it says that sessions are enabled.  When I attempt to trigger a session, a cookie is generated in my temp folder.  However, in my tutorial the page does not call the cookie apparently and the proper event is not triggered.

 

Is there any possible program that could be running in the background to prevent this?  I know my code is correct because I tested it on my remote server and it functions perfectly.  On my secondary local server computer, the code also works.

 

Link to comment
Share on other sites

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Session</title>

</head>

 

<body>

<form action="session2.php" method="post" name="form1" id="form1">

  <label for="name">Name</label>

  <input type="text" name="name" id="name" />

  <input name="Submit" type="submit" value="Submit" />

</form>

</body>

</html>

 

 

 

 

 

<?php

// initiate session

session_start();

// check that form has been submitted and that name is not empty

if ($_POST && !empty($_POST['name'])) {

  // set session variable

  $_SESSION['name'] = $_POST['name'];

  }

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Session Test 2</title>

</head>

 

<body>

<?php

// check session variable is set

if (isset($_SESSION['name'])) {

// if set, greet by name

echo 'Hello, '.$_SESSION['name'].'. <a href="session3.php">Next</a>';

}

else {

// if not set, send back to login

echo 'Who are you? <a href="session1.php">Login</a>';

}

?>

</body>

</html>

 

 

 

 

<?php session_start(); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Session Test 3</title>

</head>

 

<body>

<?php

// check whether session variable is set

if (isset($_SESSION['name'])) {

  // if set, greet by name

  echo 'Hi, '.$_SESSION['name'].'. See, I remembered your name!<br />';

  // unset session variable

  unset($_SESSION['name']);

  // end session

  session_destroy();

  echo '<a href="session2.php">Page 2</a>';

}

else {

  // display if not recognized

  echo 'Sorry, I don\'t know you.<br />';

  echo '<a href="session1.php">Login</a>';

}

?>

</body>

</html>

 

Link to comment
Share on other sites

When I say 'sessions are not working' I should be more specific.  In the above examples, a cookie is properly generated; a second blank one is also properly generated in the temp folder after the session is destroyed.  The crux of the mystery is that on my browsers, the statement triggered by $_SESSION['name'] does not occur.  Instead, I see the else statement printed.

 

I don't want to do this, but it looks like I'm out of options: time to reinstall PHP... :o

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.