Все публикации

????????? ?????? ?? HTML-???? ??? ?????? PHP ????? 2

? ??????? ????????????? (HTML-???????? input ???? radio) ??? ????????? ??????. ?? ?????? ????? ??????? ?????? ????, ??????? ? ???????? ?????????? ????. ????, ???? ??????, ????? ?? ???? ?? ????????? ?? ???????. ??????? ????????? ????????? HTML-?????:

<?php
 
  if ( count($_GET) > 0 )
  {
      if ( isset($_GET['color']) ) //--?????????, ??? ?? ??????? ???????? color
      {
          echo '?? ???????: ';
          switch( $_GET['color'] )
          {
              case 'red': echo '???????'; break;
              case 'green': echo '???????'; break;
              case 'blue': echo '?????'; break;
          }
      }
      else
      {
          echo '?? ?????? ?? ???????!';
      }
      exit;
  }
 
?>
 
<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <input type="radio" id="red" name="color" value="red" /> <label for="red">???????</label> <br />
  <input type="radio" id="green" name="color" value="green" /> <label for="green">???????</label> <br />
  <input type="radio" id="blue" name="color" value="blue" /> <label for="blue">?????</label> <br />
  <input type="submit" name="submit" value="Send" />
</form>

PHP-?????????? ????? ?????????? ????????? ????????????? ????????, ? ????? ?????????? ??????. ???????, ????? ????? ???????????? ?????????? ????? ?????????? ??????? (?? ????, ????? ????????? ??????? ????????? ??????????). ??????? ???? radio ???????????? ??????????, ???? ?? ????? ??????? checked ?? ????????? checked. ??????? ???????? ????? ? ???????, ? ???????????? ???????? ????? ??????????? ? ??????? PHP.

????????? ?????? ?? HTML-???? ??? ?????? PHP

?????????? ?????????? ? HTML-???????. ? ??????? ?????? ? ??? ??????? ?????????? ?????? ????????? ?????? ?? HTML-????, ????? ?? ?????????? ???? ?????? ????? ????????.

????, ?????? ?? HTML-???? ???????????? ??? ?????? GET ??? POST HTTP-????????. ? GET-??????? ????????? ????????? ??????????????? ? URL ? ????? ? ???????? ?????? ????????. ? POST-??????? ?????? ????????? ? ???? HTTP-??????. ?????? ???????? ????????, ????????? ? ???????? action ???? HTML-????? form, ????????, PHP-??????.

???????? ????????, ???????????? HTML-????? ? ????????, ??????????? ?????? ?? ??? ????????? ???????????? ?? ???? ???? PHP-????. ??? ?????? ? ??? ??????, ?????, ????????, ??? ???????????? ????????? ?????? ?????????? ???????? ???????? ????? ???????????? ? ??????? ?? ??? ??????. ????? ??? ???????? ????????? ?????? ????? ? ??? ??????????? ??????. ?? ??? ??????? ?? ?????????? ?????.

? ????? ?????? PHP ??????????????? ??????? ????? GET ? POST-??????????? ???. GET-????????? ??????????? ? ?????????? ??????? $_GET, POST ? $_POST.

?????????? ????? ??????:

<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <input type="text" name="name" /><br />
  <input type="submit" value="Send" />
</form>

????? ???????? ????????, ??? ???????? ???????? action ???????????? ????? PHP-???????. ?????????? $_SERVER['PHP_SELF'] ???????? ??? ? ???? ???????? ???????????? PHP-??????? ???????????? ????????? ???????? ???-???????. ????? ???????, action ?????? ????? ????????? ?? ?????? ????, ? ????????????? ?? ???????????? ? ????? ?????.

HTML-?????

??? ?? ??? ??????, ???-?????? ????? ??????????? ?????????? ???-??????? ????????? ?????????? ??? ?????? GET ? POST-????????. HTML-????? ??? ???????? ?????????? ??? ???????? ????? ????????. ?? ????, HTML-????? ???????????? ????? ???? ??? ???? ??? ????? ?????????? ?? ???-????????. ????????? ???????? HTML-????? ?????? ????? ????? ?????? ? ?????? ??? ??????????? ?? ?????.

HTML-????? ??????????? ? ??????? ??????? ???? form. ???? ??? ????? ??? ????????? ????????: method ? action. ? ???????? method ???????? ??? HTTP-??????? (get ??? post), ? action ????????????? ????????, ?? ???? ???? ? ?????, ?????? ???????? ????? ???????????. ???? ????? ???? ??? ?????????? (? ????????? ?????? ?????), ??? ? ?????????????. ????????:

<form method="get" action="/login.php">
...
</form>

?????????? ????????? ????????? ????? ????????? ??? ????? ??????, ??????? ?????????? ?????? ?????. ???????, ? ???????? ? ????? ?? ??????, ?????????? submit:

<input type="submit" value="?????" />

??????? ???????????? ????? ??????, ??????? ?? ??????? ???????? ? ?????????? HTTP-???????. ??????? value ?????? ??????? ?? ??????. ????? ????? ????????? ????????? ????????? submit. ????? ? ????????????? ????????? ??????????, ?? ????? ?????? ?? ?????? ???? ??????????? ???????, ?????????? ????????? submit ?????????? ???????? name. ????????:

<form method="get" action="/control.php">
  <input type="submit" name="submit" value="Add" />
  <input type="submit" name="submit" value="Edit" />
</form>

GET ? POST HTTP-???????. ???????? ?????????? ? HTTP-????????

?????????? ????????? ????? HTTP-????????. ??? ??????? ??????????? ? ?????? ?????? HTTP-??????, ??????? ????? ???:

<??? ???????> <????????????? ????????> <?????? HTTP>

????????:

GET /page.php HTTP/1.1

GET-??????

GET-?????? ??? ????? ???????????????? ??? HTTP-???????. ??? ?????? ???? ?????????? ?????? ????????? ?????? ????? ???-???????. HTTP-?????? ???? GET ??????? ?????? ?? HTTP-??????????, ???? ? ???? ??????????? (??? ?????????? ? ?????? "???????? ???????????????? ???-???????").

??? ?????? GET-??????? ????? ???????? ???-??????? ????????? ????????? ??????????. ????????, ???? ?? ????? ????????????? ??????????? ?????????????, ?? ? ??????? ?????????? ????? ?????????? ??? ???????????? ? ?????? ??? ????????. ?????????? ???????? ???????? ?????????? ? ??????? GET-???????.

?????????? ????????? ???-??????? Apache

?????????? ????????? ????? ?????? ???????? ?????????????? ???-??????? ? ????????????????? ????????. ??? ????????? HTTP-??????? ???-?????? ????????? ?????????? ?????????, ?????? ? ??? ????????? ??????????: IP-????? ???????, ????????????? ????????, ????????? ??????? ? ?.?. ??? ???????? ?????????? ??????-?????? ??????????????? ????????? ????? ?????? ? ?????????? ????????? ???-???????, ?????????????, ??? ???????? ???? ????????????? ??????????. ??????? ?????????? ???????? ?????????? ????????? ???-??????? Apache:

SERVER_NAME ???????? ???????? ??? ???????. Apache ????????????? ?????????? ??? ??? ??????????? ????, ?? ???????? ????????? ??????;
SERVER_ADDR IP-????? ???????. ??????????????? ?????, ?? ???????? ???????? ?????????? ??????;
SERVER_PORT ???? ???????. ??????????????? ????, ?? ???????? ???????? ?????????? ?????? (??? ????? ????, ??????? ?? ????????? 80 ??? ???-????????);
REMOTE_ADDR IP-????? ???????;
DOCUMENT_ROOT ???????? ??????? ???-??????? (???? ???????? ???????????? ?????);
REQUEST_METHOD ??? HTTP-???????;
REQUEST_URI ???? ? ?????????????? ????????? (??, ??? ?????????? ?????? ?????????? ? ?????? ?????? HTTP-???????);
QUERY_STRING ?????? ?????????? ??????? (?? ???? ??????????? ????????? ? ????????? ??????);
HTTP_HOST ???????? ???????? ????????? Host HTTP-???????. ? ??????????? ??????? ????????? ? SERVER_NAME;
HTTP_USER_AGENT ???????? ???????? ????????? User-Agent HTTP-???????. ? ???? ????????? ?????? ???????? ?????????? ? ????: ?????? ???????????? ???????, ????????, ? ?.?.;
HTTP_REFERER ???????? ???????? ????????? Referer HTTP-??????? (?? ???? ????? ????? ????????? ??????).

? ?????????? ????????? Apache ???????? ?????? ?????? PHP-????????. ??? ??? ????????? ? ?????????? PHP-??????? $_SERVER.