Page 1 of 1

Problem creating sessions

Posted: Thu Feb 26, 2004 8:03 pm
by manish_7in
Hi
I am using PHP 4.3.4 on Apache 2.0.48 running on WinXP pro.
I am trying to create a session using PHP. my script is as follows:

<?
session_start();
$counter=1;
print($counter);
$counter++;
session_register("counter");
?>

But when i run this script on my local pc(apache 2.0.48, php 4.3.4 installed) i get the following messages: -


Warning: session_start(): open(/tmp\sess_686a7d32a236d9381de7dd2eaa5bfb21, O_RDWR) failed: No such file or directory (2) in D:\inetpub\wwwroot\New Text Document.php on line 2

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at D:\inetpub\wwwroot\New Text Document.php:2) in D:\inetpub\wwwroot\New Text Document.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at D:\inetpub\wwwroot\New Text Document.php:2) in D:\inetpub\wwwroot\New Text Document.php on line 2
1
Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

Warning: Unknown(): open(/tmp\sess_686a7d32a236d9381de7dd2eaa5bfb21, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0



i have added d:\inetpub\wwwroot\tmp\ to the php.ini file as session.save_path

Can anybody tell me whats the problem or do i have to make some adjustments to the apache or php configurations.

Posted: Tue Mar 02, 2004 6:07 pm
by ckuipers
It seems to me that you haven't updated your php.ini file with the path to the directory you want your session to be saved in. Your ini file is still putting it in /tmp which is the default setting. Do you have a /tmp folder on your C: ?
When you run this script, can you see the session appear in your designated folder? If you don't create a /tmp folder on your C: drive and you'll probably see the session files appear there.

Secondly, I find it easier to register variables like this

Code: Select all

$HTTP_SESSION_VARS&#1111;'variable_name']= $variable_value;
I believe you can also use $_SESSION but you'll have to see in the docs for that.

Thirdly, you have to do all your session processing before you send anything to the browser. This means that you shouldn't print or echo anything before you do your register.

Hope this helps.

Posted: Wed Mar 03, 2004 4:31 am
by twigletmac
From the error message it would appear that PHP is using a different php.ini to the one that you edited (it thinks the folder is /tmp) - put the following into a file and run it and see where PHP thinks the php.ini is:

Code: Select all

<?php phpinfo(); ?>
Once you've sorted your php.ini file then you should change that session code to:

Code: Select all

session_start();
$_SESSION['counter'] = 1;
echo $_SESSION['counter'];
++$_SESSION['counter'];
session_register() is deprecated and using $_SESSION is much easier.

Mac