Why won't this Session Work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
theoph
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA

Why won't this Session Work?

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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'];
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
theoph
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA

Post by theoph »

Code: Select all

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

Thanks much! :D
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

if the problem is solved put
[Solved] into the edited post's subject.


i got this from a mods profiles=p
Post Reply