[thelist] php session_start() function

Santilal Parbhu santilal at scorpioneng.co.nz
Sat Apr 8 15:33:35 CDT 2006


Hi

I have been trying to write a login page for a website.  I want to restrict
certain pages of the site, and control this with a username and password. I
am having trouble with the first part of a series of scripts to do this.  My
problem is with the session_start() and session_destroy() functions.  Here
is the script:

<?php
//
// Function that returns the HTML FORM that is
// used to collect the user-name and password
//
function login_page($errorMessage)
{
  // Generate the Login-in page
  ?>

<!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.0 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd" >
  <html>
  <head>
     <title>Login Page</title>
  </head>
  <body>
    <h2>Login Page</h2>
    <form method="POST" action="authenticate.php">

  <?
  // Include the formatted error message

  if (isset($errorMessage))
    echo
      "<h3><font color=red>$errorMessage</font></h3>";

  // Generate the login <form> layout
  ?>
    <table>
      <tr><td>Enter your user-name:</td>
          <td><input type="text" size=10
                   maxlength=10
                   name="formUsername"></td></tr>
      <tr><td>Enter your password:</td>
          <td><input type="password" size=10
                   maxlength=10
                   name="formPassword"></td></tr>
    </table>
    <p><input type="submit" value="Log in">
    </form>
    </body>
  </html>
  <?
}

//
// Function that returns HTML page showing that
// the user with the $currentLoginName is logged on
//
function logged_on_page($currentLoginName)
{

  // Generate the page that shows the user
  // is already authenticated and authorized
  ?>

<!DOCTYPE HTML PUBLIC
      "-//W3C//DTD HTML 4.0 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd" >
  <html>
  <head>
     <title>Winestore</title>
  </head>
  <body>
    <h2>Winestore</h2>
    <h2>You are currently logged in as
        <?=$currentLoginName ?></h2>
    <a href="example.9-10.php">Logout</a>
  </body>
  </html>
  <?
}
// Main
session_start();

// Check if we have established a session
if (isset($HTTP_SESSION_VARS["authenticatedUser"]))
{
  // There is a user logged on
  logged_on_page(
          $HTTP_SESSION_VARS["authenticatedUser"]);
}
else
{
  // No session established, no POST variables
  // display the login form + any error message
  login_page($HTTP_SESSION_VARS["loginMessage"]);
 $errorMessage= $HTTP_SESSION_VARS["loginMessage"];
print "The error is:$errorMessage";
  session_destroy();
}
?>

When I run it I get the following error:

Warning: open(/tmp\sess_c27a0a85456411904f81baebeda8e71d, O_RDWR) failed: m
(2) in c:/program files/abria
merlin/apache/htdocs/gameon/pages/alexbasketball/login.php on line 93

Line 93 is //Main
Line 94 is session_start();

I also get the error:

Warning: Session object destruction failed in c:/program files/abria
merlin/apache/htdocs/gameon/pages/alexbasketball/login.php on line 109

Line 109 is session_destroy();

I have scoured through several texts that I have, and I have scoured the net
for an answer to this problem, but I can't find anything.  I am using php
version 4.0.4 and I am using Windows xp.

Can anyone help.  I was wondering if it was trying to open a temporary file
that didn't exist and I am suppose to create one somewhere or something
liken that.

Thank you.

Regards

Santilal






More information about the thelist mailing list