...

View Full Version : doubt in session.pls help me........



mds8000
08-01-2007, 01:08 PM
hi friends,
i'm a .net developer........but unfortunately i took a project which i've to code in php. in that i've to use SESSION............. i wrote a sample program to check the session. but it is not working........the two files are sess1.php and sess2.php...........

program for sess1.php is below;

<html>
<head>
<title>PHP session Test</title>
<?php
session_start();
?>
</head>

<body>
<p>This is an HTML line
<p>
<?php
$_SESSION['hi']="hi to all";
echo $_SESSION['hi'];
?>
<a href="sess2.php">goto 2nd</a>
</body></html>

the program for sess2.php is below;

<html>
<head>
<title>PHP session Test</title>
<?php
session_start();
?>
</head>
<body>
<p>This is an HTML line
<p>
<?php

echo ($_SESSION['hi']);

?>

</body></html>

first i stored a string in a session in sess1.php...then it is accessed at page 2 i.e., sess2.php...........there is a link in first page to go sess2.php........
in second page it is displaying only "This is an HTML line"............it is not displaying "hi to all"..............what i've to do?
please help me friends...........

timgolding
08-01-2007, 01:20 PM
try session_start at the very top of the page before any output.

mds8000
08-01-2007, 03:12 PM
thanx friend,
it is working in the web server. but it is not working in my pc.
it shows.....


Warning: session_start() [function.session-start (http://www.codingforums.com/function.session-start)]: open(/tmp\sess_859b750aa43761ec312cce96d0298a18, O_RDWR) failed: No such file or directory (2) in C:\Program Files\Apache Group\Apache2\htdocs\sess1.php on line 2

Warning: session_start() [function.session-start (http://www.codingforums.com/function.session-start)]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\sess1.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\sess1.php on line 2

Warning: session_start() [function.session-start (http://www.codingforums.com/function.session-start)]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\htdocs\sess1.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\sess1.php on line 2
This is an HTML line
hi to allgoto 2nd (http://www.codingforums.com/sess2.php)
Warning: Unknown: open(/tmp\sess_859b750aa43761ec312cce96d0298a18, 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

-----------------------------------
what i've to do?

rafiki
08-01-2007, 03:19 PM
does this work


<?php
session_start();
$_SESSION['hi'] = "Hello everyone";
?>
<html>
<head>
<title>PHP session Test</title>
</head>

<body>
<p>This is an HTML line</p>
<?php
echo $_SESSION['hi'];
?>
<a href="sess2.php">goto 2nd</a>
</body></html>

then sess2.php should have


<?php
session_start();
?>
<html>
<head>
<title>PHP session Test</title>
</head>

<body>
<p>This is an HTML line</p>
<?php
echo $_SESSION['hi'];
?>
</body></html>

timgolding
08-01-2007, 03:49 PM
2 of those errors say

Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\sess1.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\sess1.php on line 2

thats because the session start still wasnt run before the headers were sent. Im unsure of the other error

CFMaBiSmAd
08-01-2007, 03:50 PM
So, did you read the first error message (the other error messages are due to the fact that the first error message was output to the browser) -

Warning: session_start() [function.session-start]: open(/tmp\sess_859b750aa43761ec312cce96d0298a18, O_RDWR) failed: No such file or directory (2) in C:\Program Files\Apache Group\Apache2\htdocs\sess1.php on line 2I would be checking if there is a folder by that name that on your computer (also reading the PHP manual section on Sessions will suggest the same.)

mds8000
08-01-2007, 03:53 PM
the above code is working in the web server's.........but not in my PC........it is showing the above Warnings when i start loaded the first page(sess1.php) in IE..........i think i've to do some changes in the php.ini............wat i've to do?

CFMaBiSmAd
08-01-2007, 04:07 PM
Also, reading the last two error messages -

Warning: Unknown: open(/tmp\sess_859b750aa43761ec312cce96d0298a18, 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

Pretty simple - create a folder called tmp in the root folder of your hard drive where you installed PHP so that the session data files have a place they can be written to.

mds8000
08-01-2007, 08:36 PM
thank u very much...............



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum