Web Hosting Talk







View Full Version : Session in PHP


mithilesh
12-18-2001, 04:44 PM
Actually I want to create the session variable in PHP here is my script


<?
session_start();
session_register('session_variable');
$session_variable = $session_variable ? $session_variable + 1 : 20;
echo $session_variable;
?>

But it is not running properly and when I try to execute it ,It shows following page(ERROR)


Warning: Cannot send session cookie - headers already sent by (output started at d:\mith\php\session_v.php:3) in d:\mith\php\session_v.php on line 4

Warning: Cannot send session cache limiter - headers already sent (output started at d:\mith\php\session_v.php:3) in d:\mith\php\session_v.php on line 4

Warning: open(D:\mith\PHP\sessiondata\sess_ee992a9b15414092726e9e005d28699f, O_RDWR) failed: No such file or directory (2) in d:\mith\php\session_v.php on line 4

Warning: Undefined variable: session_variable in d:\mith\php\session_v.php on line 6
20
Warning: open(D:\mith\PHP\sessiondata\sess_ee992a9b15414092726e9e005d28699f, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (D:\mith\PHP\sessiondata) in Unknown on line 0<br



Please help me for solving this problem.

Thank you

zupanm
12-18-2001, 05:19 PM
thats a common error when using sessions for the first time. sessionstart() needs to be called before any output is sent to the browser, much like a cookie. Make sure you don't output ANY html to thew browser. That even includes <html> and such tags like that. If that isn't a problem here is another problem. If you have you <? at the top make sure there isn't an empty line above it. That'll cause it to give errors like you pasted.

Mike

mithilesh
12-18-2001, 05:24 PM
yes I now my script is running I had used <html> tag at top of page now I correct it and thanks for your help.