In php I know only the basics. Now it took to work with requests. Just want to see examples of processing these requests and how it works. Thought up to this:

<?php echo "Привет, $_GET['name'] !"; ?> 

In the browser I enter http://localhost/script.php?name=Vasiliy . It seems to be "Hi Vasiliy", but the error is:

Parse error: syntax error, T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in Z: \ home \ localhost \ www \ get.php on line 2

Where is the mistake? Please provide examples of simple Get and Post requests. I do not plan to use forms yet, I want from the address bar of the browser. And please do not forget the comments. ))

  • one
    post request from the address bar ... cool. - FLK
  • Hmm ((((stupid with quotes (((stupid ... What about the Post? The difference between the post and get understand. - hooko
  • @hooko, then you must understand that the POST address bar is not sent. - Sh4dow
  • about the address bar, I mean get - hooko

3 answers 3

 <?php echo "Привет, $_GET[name] !"; // Первый вариант echo 'Привет, '.$_GET['name'].' !'; // Второй вариант ?> 
  • @hooko, $_POST - data array transmitted via post-request - KiTE
  • one
    <? php echo "Hi, {$ _GET ['name']}!"; // The third option?> - barsukov
  • echo "Hello,", $ _ GET ['name']; // fifth and most faithful) - FLK
  • one
    Yes, examples can be nemeryanno. One more: printf ('Hi% s!', $ _GET ['name']); printf and sprintf appropriate if the welcome string is set as a constant in a separate module. Especially useful if you are doing a multilingual site. And all these examples are correct if the interpreter does not display an error :). The main thing is to understand how each of them works, and what it builds in a given situation. - KiTE

$ _GET is a global array for get requests.

$ _POST is a global array for post requests.

$ _REQUEST is a global array for get and post requests.

get:

 адресная строка: some_site.com?var=hello 

code:

 echo $_GET['var'];//hello echo $_REQUEST['var'];//hello echo $_POST['var'];//Notice: Undefined index: var in ... 
     <?php echo "Привет, {$_GET['name']} !"; ?> 

    It is necessary to shield a variable in this case by such an example. Good luck.