Jump to content

Session basics and help


paruby

Recommended Posts

Hello all -

 

I am looking for advice and help w/ Sessions.  First, what I am trying to do - have a user login, and set their username as a session variable.  I am trying to avoid using cookies, as my users may not have cookies enabled, and also try to get away w/out sending variables via the URL.  My pages are as follows:

 

index.php:

<FORM ACTION="login.php" METHOD="POST">
<table align="center">
<tr>
	<td>Name:</td>
	<td><input type="text" align="LEFT" name="txtName" size="20"></td>
</tr>
<tr>
	<td>Email:</td>
	<td><input type="text" align="LEFT" name="txtEmail" size="20"></td>
</tr>
<tr>
	<td colspan = "2"><input type="Submit" value="Submit" name="CmdLogin"></td>
</tr>
</table>
</form>

 

login.php:

<?php
if (isset($_POST['CmdLogin']))   {
$thisEMail = $_POST['txtEMail'];
$thisName = $_POST['txtName'];
session_start();
$_SESSION[username] = $thisName;
echo "Session Username = [".$_SESSION[username]."]<br>";
echo "<a href='eventList.php'>Events List</a>";
}
?>

 

On the above page, the value prints out...

 

eventList.php:

<?php 
echo "Session Username = [".$_SESSION[username]."]<br>"; 
?>

 

On th above page, the value does not print.

 

If I print out the "session_id" on the login.php page, and send it via url, it then also prints on the eventList.php page, but the original $_SESSION[username] value still does not...

 

My session_globals value in my ini is set to false.  What am I missing, and can I do this without sending variables via the URL?  I have also read that some session components will be removed for PHP 6.  I am using PHP 5.

 

Thanx!

Link to comment
Share on other sites

You need session_start(); at the top of every page that you want to use sessions on.

 

Read the PHP manual for how it functions, and you will see that if there is already an existing session, it will use that one instead of creating a new one.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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