hey all,

Im trying to figure out an issue with PHP sessions on windows 2003 server.

Im currently using php 5.2.4 on Windows 2003 server and iis 6. I can run phpinfo() just fine and it displays lots of information on my php version.

My issue is the following.

Sessions. I do not seam to have the ability to keep my sessions active. I see the session files be created... and data is being put into those files... but yet my other pages do not mean to be able to get my session data.

On every page i have session_start(), but when i try and call my session's.. they are all blank.

So what im asking is for someone to provide code to me that is known to work under a windows install of php that will display session data. This way i can rule out my server... and ensure that it's my code.

Thanks.

    here is what i put together.

    index.php

    <?php session_start(); ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    //php file created to test php session under zockprog account
    
    if($_POST['Submit'] !== 'Submit')
    	{
    	echo 'this forum is not submitted <br >';
    	echo'<form name="form1" method="post" action="">
      		 text box data
        	 <input type="text" name="textfield"> 
        	 <input type="submit" name="Submit" value="Submit">
    		 </form>';
    	}
    
    if($_POST['Submit'] == 'Submit')
    	{
    	$_SESSION["data"] == $_POST['textfield'];
    	echo $_POST['textfield'].'<br >';
    	echo 'forum is submitted';
    	include 'view_data.php';
    	;
    	}
    ?>
    
    
    </body>
    </html>
    

    view_data.php

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    echo 'the data that was submitted was '.$_SESSION["data"];
    ?>
    
    </body>
    </html>

    and the session data does not print.

      You need a session_start() in the second file before the $_SESSION array is ever referenced (and of course before any output is generated).

        Check your phpinfo's session save path and verify it is being written to.

          Also, you should be able to verify that sessions are working on a single page

          <?php
            session_start();
            echo session_id();
            $_SESSION['foo'] = 'bar';
            echo '<br />'.$_SESSION['foo'];
          ?>

            The problem I see in your code is a simple coding error. This:

            $_SESSION["data"] == $_POST['textfield'];

            does not assign any data to $_SESSION["data"]. The assignment operator is a single equal sign '=' .

              Write a Reply...