Board index   FAQ   Search  
Register  Login
Board index PHP PHP Installation

PHP Can't Handle Sessions

Forum for you who has PHP installation issues

Moderators: macek, egami, gesf

PHP Can't Handle Sessions

Postby batookee » Sun Dec 07, 2003 7:13 pm

I have Apache 2.0 and PHP 4 installed on my WinXP pro box.
I've been trying to run several scripts that call on session management and for some reason it isn't on or isn't working properly. Here are the errors I get:

Code: Select all
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

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\apache\Apache2\htdocs\Xplorer\index.php:3) in C:\apache\Apache2\htdocs\Xplorer\index.php on line 3

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\apache\Apache2\htdocs\Xplorer\index.php:3) in C:\apache\Apache2\htdocs\Xplorer\index.php on line 3


Can anyone help me setup the session management or point me to a tutorial?

Thanks
batookee
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Dec 07, 2003 7:09 pm

Re: PHP Can't Handle Sessions

Postby swirlee » 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).
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby batookee » Mon Dec 08, 2003 2:39 am

Wow, that makes sence! heh Thanks man
batookee
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Dec 07, 2003 7:09 pm

2 days and counting..

Postby EdwardBobadilla » 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!
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

try this code

Postby ruturajv » 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);
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

didnt work.

Postby EdwardBobadilla » 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?
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

Postby Redcircle » 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
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby swirlee » 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.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Redcircle » 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.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA


Return to PHP Installation

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron