Sessions and variable values.

A

Anonymous

Guest
I attempted the same tutorial as "harmon808" with some success:

Page 1
Code:
<?php

session_start(); 

$_SESSION['name'] = 'Jester';

?>

page 2

Code:
<?php

session_start();

echo 'Hello '.$_SESSION['name'];

?>

This code creates a session variable in the /tmp folder and the code is executed accordingly.

Problem:

How do I allow the user to specify what the value of the variable "name" is?
 
Code:
<?php
session_start();

  if($_POST['posted']) {

$_SESSION['name'] = $_POST['specifytext'];


} else {

//do something

}
?>

<form action="<?php echo basename(__file__);?>" method="post">
<label for="specifytext">Your username</label>
<input type="text" id="specifytext" name="specifytext"/>

<input type="submit" name="posted" id="posted">
</form>
Offcourse, you should validate the username too
 
Hiya Dabear!

Could you explain what is happening in the code please :help:
 
he created a form. the user puts his name in the form and hits submit. When he hits submits it puts the name in the session var.
 
Back
Top