Jump to content

php session variables.....


chandru_cp

Recommended Posts

Well I was beaten to the answer, but I'll expand on, and complement the post by Anzeo.

 

Setting session-variables are easy.

 

<?php
session_start();

if(isset($_POST['action'])){
	$_SESSION['username'] = $_POST['username'];
	$_SESSION['password'] = $_POST['password'];
	echo 'Hello, '.$_SESSION['username'];
}

echo '<div><form action="'.$_SERVER['PHP_SELF'].'" method="post">';
echo '<input type="text" name="username"><br />';
echo '<input type="text" name="password"><br />';
echo '<input type="submit" name="action" value="Go"><br />';
echo '</form></div>';
?>

 

A couple of things about this code:

1) session_start must at the beginning of the script (or at least before ANY output or $_SESSION variables are used)

2) You should NEVER store a user's password inside a $_SESSION variable. Doing so is very a insecure practice.

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.