close

Вход

Забыли?

вход по аккаунту

?

Webforms with PHP

код для вставкиСкачать
Web Forms with PHP
COEN 351
Displaying and processing a
simple form
hello.php
if( array_key_exists(�my name’,$_POST)) {
print “Hello, “.$_POST[�my_name’];
} else {
print <<<_HTML_
<form method=“post” action=“$_SERVER[PHP_SELF]”>
Your name: <input type = “text” name = “my_name”>
<br/>
<input type = “submit” value=“Say Hello”>
</form>
_HTML_;
}
Displaying and processing a
simple form
Web Server
Web Browser
Get /hello.php
Check whether there
is a variable my_name
in $_POST hash
No: Send form
Displaying and processing a
simple form
Web Server
Web Browser
No: Send form
Your name:
Say Hello
<form method
…
</form>
Displaying and processing a
simple form
Web Server
Web Browser
Your name: Emil
Say Hello
“POST /hello.php”
my_name = Emil
Displaying and processing a
simple form
Web Server
Web Browser
Get /hello.php
Hello, Emil
There is a value for
my_name
Displaying and processing a
simple form
hello.php
if( array_key_exists(�my name’,$_POST)) {
print “Hello, “.$_POST[�my_name’];
} else {
print <<<_HTML_
<form method=“post” action=“$_SERVER[PHP_SELF]”>
Your name: <input type = “text” name = “my_name”>
<br/>
<input type = “submit” value=“Say Hello”>
</form>
_HTML_;
}
Displaying and processing a
simple form
пЃ®
$_Server is an auto-global array with
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
$_Server[’PHP_Self’] pathname part of the current request’s URL
QUERY_STRING part of the URL after �?’ character
PATH_INFO extra path information tacked onto the end of the URL
after the name of the resource
SERVER_NAME
DOCUMENT_ROOT
REMOTE_ADDR
REMOTE_HOST
HTTP_REFERER
HTTP_USER_AGENT
$_POST array is an auto-global array:
пЃ®
пЃ®
Keys are form element names
Values are values of the form elements
Displaying and processing a
simple form
пЃ®
пЃ®
Example is of course horrendously insecure
Some functions needed for sanitization:
пЃ®
пЃ®
strip_tags removes all html tags
html_entities replaces special html characters with
their entity equivalents:
пЃ®
пЃ®
пЃ®
пЃ®
< to &lt
> to $gt
& to &amp
“ to &quot
Документ
Категория
Без категории
Просмотров
48
Размер файла
76 Кб
Теги
1/--страниц
Пожаловаться на содержимое документа