Jump to content

[SOLVED] Ok im a noobe! Question about Variables


vajra_hendry

Recommended Posts

Ok so I know how to create the variables.  Thats no problem.  I understand how to post values to the variables using forms / links.  The problem is simple :

 

If some on my site selects a link that changes a variable e.g.

 

$var1 = 10

 

So thats cool but in about 10 mins time the script will need to go back to $var1 and refer to the value that the user previoulsy selected.  So in this case the value is 10!

 

So lets says seconds later after $var1 was set to '10' somone else logs into my site and clicks another link that changes $var1 = 20

 

So that would screw things up I guess.  So that variable that is being changed, is it specific to the user who set it, or is the variable centrally located on the server?

 

Cos potentially what now happens is my customer (yeah the one that set $var1 to 10) gets to the part in the script and it recalls $var1 = 20 so the customer is going to be like . . . well thats wrong, I selcted a different option!

 

God does that make sense!! haha.  Any help for a humble noob would be welcomed

 

Thanks

Hmm, I'm a little confused by what you are saying.  But I'm pretty sure that sessions will help.  Try the following:

 

<?php
session_start();
print "Old value was " . $_SESSION['var'] . "<br>";
$_SESSION['var'] = $_GET['var'];
print "New value is " . $_SESSION['var'];
?>
<form action="" method=get>
<input name=var type=text value="<?php echo $_SESSION['var']; ?>">
<input name=Submit type=Submit value=Submit>
</form>

 

When you use session_start(), all variables inside $_SESSION are remembered until the user closes the browser (at least with default configurations)

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.