You are here: Re: [PHP] »Ø¸´:Re: [PHP] about session « PHP « IT news, forums, messages
Re: [PHP] »Ø¸´:Re: [PHP] about session

Posted by Richard Lynch on 10/12/75 11:14

On Sat, April 23, 2005 4:06 am, bitblackbug@sohu.com 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация