Page 1 of 1

Why won't this Session Work?

Posted: Tue Feb 28, 2006 3:46 pm
by theoph
Located at the top of the web page:

Code: Select all

<?php 
	session_start();
	session_register('ekk');
	$ekk = "Testing";
?>
Code of the form of the same page.

Code: Select all

<body>
<form id="sessiontest" name="sessiontest" method="post" action="test5.php">
  <table width="200" border="1" align="center" summary="Using this form to test the functioning of Session Variables.">
    <caption align="top">
      Test Form
    </caption>
    <tr>
      <th bgcolor="#C3D2F0">Text</th>
      <td><input name="txtfld" type="text" id="txtfld" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <th bgcolor="#C3D2F0">Date</th>
      <td><input name="datefld" type="text" id="datefld" /></td>
      <td><input name="Button" type="button" onclick="KW_expertCalendar('January','February','March','April','May',
'June','July','August','September','October','November','December','Su','Mo','Tu','We','Th','Fr','Sa','datefld','y','-','mm','-',
'dd','0','0','0','-1','-1','-1','0',this,-1,-1,210,155,'kaosjs/images/leftarrow.gif','kaosjs/images/rightarrow.gif',
'kaosjs/images/leftarrow.gif','kaosjs/images/rightarrow.gif','',0,'kaosjs/cal1.css','#ffffff',1)" value="Insert Date" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><div align="center">
        <input type="submit" name="Submit" value="Submit" />
      </div></td>
      <td></td>
    </tr>
  </table>
</form>
</body>
The following is the php script at the start of the page that the form is directed to.

Code: Select all

<?php session_start();?>
The following is the table to display the variable.

Code: Select all

<body>
<table border="1" align="center" summary="Table to receive the variable information.">
  <caption align="top">
    Session Test Results
  </caption>
  <tr>
    <th bgcolor="#C3D2F0">Session Variable </th>
    <td>
		<?php
			if (isset($_SESSION["ekk"])) {
				echo $_SESSION["ekk"];
			}else {
				echo $ekk;
			}
			?>
	</td>
  </tr>
  <tr>
    <th bgcolor="#C3D2F0">Form (txtfld) </th>
    <td><?php echo $_POST['txtfld'];?></td>
  </tr>
  <tr>
    <th bgcolor="#C3D2F0">Form (datefld) </th>
    <td><?php echo $_POST['datefld'];?></td>
  </tr>
</table>
</body>
My PHP Session Settings.

Image


feyd | edited to make code wrap.

Posted: Tue Feb 28, 2006 3:49 pm
by John Cartwright
Have you read the cautions of using session_register?

:arrow: http://ca3.php.net/session_register

why not avoid session_register all together?

page1.php

Code: Select all

session_start();
$_SESSION['eek'] = 'foobar';
page2.php

Code: Select all

session_start();
echo $_SESSION['eek'];

Posted: Tue Feb 28, 2006 3:54 pm
by feyd
Lose session_register(), it's deprecated, therefore shouldn't be used. Use $_SESSION['ekk'] instead.

There may be other reasons it's "not working" but unfortunately, we'll need more information to help. Specifically, does the first page create the cookie? PHP may not be able to create the session data store due to having session.save_path nulled.

Posted: Tue Feb 28, 2006 4:05 pm
by theoph

Code: Select all

<?php $_SESSION['ekk'] = 'foobar';?>
Worked!

Thanks much! :D

Posted: Tue Feb 28, 2006 6:46 pm
by a94060
if the problem is solved put
[Solved] into the edited post's subject.


i got this from a mods profiles=p