Re: »Ø¸´:Re: [PHP] about session

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, April 23, 2005 4:06 am, bitblackbug@xxxxxxxx said:
> that 's say I must session_register at fitst ,and use $_SESSION['time'] at
> secoend?


In theory, these two are the same:

<?php
  session_register('time');
  $foo = time();
?>

<?php
  $_SESSION['time'] = time();
?>

However, the session_regsiter is the "old way" and is deprecated.

So, don't do that in any new code you write.

Or, to think of it another way, just doing $_SESSION['foo'] = 42; will
automatically 'register' the variable/value in your session data for you
and give it a value all in one step.

It's much more convenient than the "old way"

> and How can i get the value of the form's element?

A form's element has *NOTHING* to do with a $_SESSION variable, unless YOU
decide to make them interact.

You get FORM elements with $_POST.

Example:

<?php
  if (isset($_POST['foo'])){
    echo "foo is $_POST[foo]<hr />\n";
  }
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  <input name="foo" value="bar"><br />
  <input type="submit" value="Click Me!">
</form>

> just use $time ?

If you want read the FORM data, use $_POST['time'];
If you want read/write the SESSION data, use $_SESSION['time'];

You might want to take the 'time' put in by the user in a FORM on one
page, and store it in a SESSION so you have it on later pages, and then,
eventually, you will put it in your database.

On the SECOND page, after they hit submit on the FORM page, you would have
this:

<?php
  $_SESSION['time'] = $_FORM['time'];
?>

You would then use something like this, later, when you put it in the
database:
<?php
  $time = $_SESSION['time'];
  $query = "insert into ... (time, ...) values('$time', ...)";
?>

You would also want to make sure that the $time provided by the user was
REASONABLE and not an SQL Injection attack.  Google for "sql injection"
for more info about that.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux