Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question doubt in session.pls help me........

    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...........

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    try session_start at the very top of the page before any output.
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy s..it s working in the web server.....but not in my PC...

    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]: 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]: 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]: 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
    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?

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    does this work
    PHP Code:
    <?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 Code:
    <?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>

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    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
    You can not say you know how to do something, until you can teach it to someone else.

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    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 2
    I 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.)
    Last edited by CFMaBiSmAd; 08-01-2007 at 02:52 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb what i've to do in php.ini file to use session?

    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?

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #9
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile s............now it is working........

    thank u very much...............


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •