Jump to content

[SOLVED] how do you do this?


ballhogjoni

Recommended Posts

How do you lock a variable so that when you refresh a page it doesn't disapear?

 

You don't under normal circumstance. HTTP has no state.

 

<?php

 session_start();
 if (!isset($_SESSION['started'])) {
   $_SESSION['started'] = $_POST['variable'];
 }

 echo $_SESSION['started'];

?>

How do you lock a variable so that when you refresh a page it doesn't disapear?

 

example:

$variable = $_POST['variable'];

 

then I refresh the page but I want the $variable to still hold its value. I tried:

 

$_SESSION['variable'] = $_POST['variable'];

 

but that din't work.

 

Try this;

 

session_start();

$_SESSION['variable']=($_SESSION['variable']&&!$_POST['whatever'])?$_SESSION['variable']:$_POST['whatever'];

echo"<input type='text' name='whatever'".(($_SESSION['variable'])?" value='$_SESSION[variable]'":'')."/>";

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.