PHP Can't Handle Sessions

Forum for you who has PHP installation issues

Moderators: egami, macek, gesf

Post Reply
User avatar
swirlee
Moderator
Moderator
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Sun Dec 07, 2003 7:40 pm

batookee wrote:[code]
Warning: session_start(): open(/tmp\sess_d85669851e0b2830838acd86482806bb, O_RDWR) failed: No such file or directory (2) in C:\apache\Apache2\htdocs\Xplorer\index.php on line 3


This is the one that matters. Sessions require a place to be stored, and this place is indicated in your php.ini by "session.save_path". The default is /tmp. If that directory doesn't exist, PHP pukes, as above. So, either you need to create a directory called /tmp, or you need to switch your session.save_path to another one that does exist (e.g. /windows/temp).
Image

EdwardBobadilla
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Dec 20, 2003 11:38 am
Location: Altadena, Pasadena, Orange County, Los Angeles
Contact:

Mon Dec 22, 2003 4:30 pm

My sessions dont work, and ive followed all of those steps "/tmp" --> "C:\temp" and register_globals = off and numerous others. Ive narrowed it down to this. The session files are being created, I can store data into an SQL database, but i Just cant transfer data to a session file for some reason, even tho the session files are generated but all contain this.

"first_name|N;last_name|N;email_address|N;special_user|N;user_level|s:1:"0";"

I have apache 1.3 w/ PHP 4.3 and my session variables in the PHP.INI are correct. Is there a list of steps i should try? Here is an example of what my scripts contain and what it does.

Code: Select all


1st file = "checkuser.php"
<?
/* Check User Script */
session_start();  // Start Session

include 'db.php';
// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];

if((!$username) || (!$password)){
   echo "Please enter ALL of the information! <br />";
   include 'login_form.html';
   exit();
}

// Convert password to md5 hash
$password = md5($password);

// check if the user info validates the db
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
   while($row = mysql_fetch_array($sql)){
   foreach( $row AS $key => $val ){
      $$key = stripslashes( $val );
   }
      // Register some session variables!
      session_register('first_name');
      $_SESSION['first_name'] = $first_name;
      session_register('last_name');
      $_SESSION['last_name'] = $last_name;
      session_register('email_address');
      $_SESSION['email_address'] = $email_address;
      session_register('special_user');
      $_SESSION['user_level'] = $user_level;
      
      header("Location: login_success.php");

      mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");
      
   }
} else {
   echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br />
   Please try again!<br />";
   include 'login_form.html';
}
?>

2nd file = "login_success.php"

<?
session_start();

echo "Welcome ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."! You have made it to the members area!<br /><br />";

echo "Your user level is ". $_SESSION['user_level']." which enables you access to the following areas: <br />";

if($_SESSION['user_level'] == 0){
   echo "- Forums<br />- Chat Room<br />";
}
if($_SESSION['user_level'] == 1){
   echo "- Forums<br />- Chat Room<br />- Moderator Area<br />";
}

echo "<br /><a href=logout.php>Logout</a>";

?>


And the output is..

Welcome ! You have made it to the members area!

Your user level is which enables you access to the following areas:
- Forums
- Chat Room

Logout

Notice the

Code: Select all

$first_name and $last_name
do not exist? also the user level is not present? Can you tell me what could be causing this to happen?

I also have a router, im using apahce 1.3 w/ php4.3, i switched from apache2 to apache 1.3, no luck. Please help!

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1279
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Mon Dec 22, 2003 9:19 pm

try this code and see if session varible is registered

Code: Select all

<?php
session_start();

$_SESSION['firstname'] = "first name";

if (isset($_SESSION['firstname'])) {
  echo "Session var set and is " . $_SESSION['firstname'];
else {
  echo "Session var not set";
}
?>


if this works then session vars are being set
then try the if code on other page [redirected page]
and then see if you get the value
IF NOT then the session is not being carried to the next page

also try this

Code: Select all

//add the session id to the redirected page
header ("location: nextpage.php".SID);

EdwardBobadilla
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Dec 20, 2003 11:38 am
Location: Altadena, Pasadena, Orange County, Los Angeles
Contact:

Tue Dec 23, 2003 12:31 pm

I tried it, the first script works, the second doesent, at first it gave me a "header output alrieghty exist" error, then i went to php.ini and set buffering ON and now it just goes to the next page and the value's are blank.

Any suggestions?

User avatar
Redcircle
Moderator
Moderator
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Thu Dec 25, 2003 11:12 am

first of all.. turn buffering off. and turn all errors and notices on..

You are using superglobals. DO NOT use session_register in conjuntion with $_SESSION

$_SESSION['first_name'] = $first_name; is fine.

Code: Select all

if($login_check > 0){
   while($row = mysql_fetch_array($sql)){
   foreach( $row AS $key => $val ){
      $$key = stripslashes( $val );
   }


you have an extra $ on the $$key

also do md5 as a database function instead of in php.

User avatar
swirlee
Moderator
Moderator
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Thu Dec 25, 2003 9:35 pm

Redcircle wrote:

Code: Select all

if($login_check > 0){
   while($row = mysql_fetch_array($sql)){
   foreach( $row AS $key => $val ){
      $$key = stripslashes( $val );
   }


you have an extra $ on the $$key


I saw this, too, but figured he was doing variable variables, e.g. creating a variable with a name equal to the value of $key. I assumed this because if you take off the extra $, it's no longer valid PHP (in a foreach(), you can't do assignment to the same array you're iterating through). This seems like a lousy way to do it (I've found that there's almost always a better way to do anything without variable variables), but it works.
Image

User avatar
Redcircle
Moderator
Moderator
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Fri Dec 26, 2003 12:27 pm

Well .. I saw the $$ and thought. he's using variable variables.. then I thought.. he's having problems with simple php, var var's are a little more advanced so looking at the code didn't cross my mind.. I just saw the $$ .. thanks for the correction.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests