Jump to content

Recommended Posts

Sorry to bug you guys with a bit of a newbie crisis...

 

I am working on the PHP for Dreamweaver book and up to sessions.  My code is perfect and the author claims there must be something wrong with my computer.  Basically, nothing involving sessions functions.  However, sessions are enabled.  I have my php.ini file in both my php5 folder and sessions path folder.

 

My only guess is that there is a problem with the sessions folder being write protected (the 'read only' check box always is filled, every time I clear it and go to check the properties, the box is filled in).

 

Thank you so much for your help.

 

Jon 

Link to comment
https://forums.phpfreaks.com/topic/82422-solved-local-sever-sessions-not-working/
Share on other sites

Check your web server log for errors to get php to help you find what the problem is.

 

There are a number of things it could be and without specific symptoms and the code that is causing those symptoms, no one in a forum can directly guess what the problem is.

Dumb question but where is my error log on my local server (on my home computer)?

 

EDIT  Here are my sample pages:

 

<!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>

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.