Jump to content

[SOLVED] Getting my head round sessions


dmccabe

Recommended Posts

Ok so I have been told that sessions are easy to use and easy to understand, so I am about to prove just how slack I am :(

 

I decided to set up a little test, so I created 2 php files, one with a form to fill in, that then sets one of the form options to a session variable and then the second one simply says welcome session variable.

 

test1.php

 

<?php 
session_start();
if (!isset($_POST['ldapname'])) {
?>

You must login below with your Windows(Citrix) username and password:

	<form method="POST" action="<?php echo $PHP_SELF; ?>" name="login">
		<table align="center">	
			<tr>
				<td>Username:</td>
				<td><input type="text" name="ldapname"></td>
				<td><a href=".." title="Click for help on this item"><strong>?</strong></td>
			</tr>
			<tr>
				<td>Password:</td>
				<td><input type="password" name="ldappass"></td>
				<td><a href=".." title="Click for help on this item"><strong>?</strong></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" value="Login" name="submit"></td>
			</tr>
		</table>
	</form>
<?php
} else {


		$_session['ldapname'] = $_POST['ldapname'];
		header("Location:test2.php");
	}
?>

 

test2.php

 

<?php 
session_start();
echo "Test 2";
echo "<br /> Welcome ".$_session['ldapname'];
?>

 

however there is never anything in $_session['ldapname'];

 

why?

Link to comment
https://forums.phpfreaks.com/topic/108841-solved-getting-my-head-round-sessions/
Share on other sites

Ok so I have been told that sessions are easy to use and easy to understand, so I am about to prove just how slack I am :(

 

I decided to set up a little test, so I created 2 php files, one with a form to fill in, that then sets one of the form options to a session variable and then the second one simply says welcome session variable.

 

test1.php

 

<?php 
session_start();
if (!isset($_POST['ldapname'])) {
?>

You must login below with your Windows(Citrix) username and password:

	<form method="POST" action="<?php echo $PHP_SELF; ?>" name="login">
		<table align="center">	
			<tr>
				<td>Username:</td>
				<td><input type="text" name="ldapname"></td>
				<td><a href=".." title="Click for help on this item"><strong>?</strong></td>
			</tr>
			<tr>
				<td>Password:</td>
				<td><input type="password" name="ldappass"></td>
				<td><a href=".." title="Click for help on this item"><strong>?</strong></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" value="Login" name="submit"></td>
			</tr>
		</table>
	</form>
<?php
} else {


		$_session['ldapname'] = $_POST['ldapname'];
		header("Location:test2.php");
	}
?>

 

test2.php

 

<?php 
session_start();
echo "Test 2";
echo "<br /> Welcome ".$_session['ldapname'];
?>

 

however there is never anything in $_session['ldapname'];

 

why?

It's $_SESSION, not $_session

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.