Metodele GET si POST

Stefanescu Mihai 2 years ago PHP
Acest articol face parte din cursul Toate lectiile PHP. Te poti inscrie la acest curs aici!

In PHP exista 2 moduri de a transmite informatii intre browser si server.

  • Metoda GET
  • Metoda POST

Metoda GET

Metoda get trimite informatiile catre server codate in URL, separate de url prin semnul ?.

http://invata-programare.ro/index.php?nume1=valoare1&nume2=valoare2&nume3=valoare3

Informatiile trimise cu ajutorul acestei metode se pot recupera cu variabila globala $_GET (care este un array asociativ ce contine toate informatiile trimise prin GET)

  • Metoda GET produce un sir de caractere lung ce apare in logurile serverului si in casuta de adrese a browserului.
  • Metoda GET este restrictionata la 1024 caractere.
  • Nu folositi metoda GET pentru parole sau alte informatii importante.
  • Metoda GET nu poate trimite date binare (ex: imagini, documente, etc) catre server.
<?php
  if( $_GET["nume"] || $_GET["varsta"] )
  {
     echo "Salut ". $_GET['nume']. "<br />";
     echo "Ai ". $_GET['varsta']. " ani.";
     exit();
  }
?>
<html>
<body>
  <form action="<?php $_PHP_SELF ?>" method="GET">
  Nume: <input type="text" name="nume" />
  Varsta: <input type="text" name="varsta" />
  <input type="submit" />
  </form>
</body>
</html>

Metoda POST

Metoda POST transmite informatia prin intermediul headerelor HTTP. Informatia este encodata ca si in cazul metodei GET si pusa intr-un array asociativ numit $_POST.

Informatiile transmise prin metoda POST merg prin geaderele HTTP, deci securitatea informatiei depinde  de securitatea protocolului (Se poate folosi Secure HTTP pentru asigurarea securitatii).

  • In cazul metodei POST nu exista restrictii de marime
  • Metoda POST poate transmite informatii in ASCII cat si in binar
<?php
  if( $_POST["nume"] || $_POST["varsta"] )
  {
     echo "Salut ". $_POST['nume']. "<br />";
     echo "Ai ". $_POST['varsta']. " ani.";
     exit();
  }
?>
<html>
<body>
  <form action="<?php $_PHP_SELF ?>" method="POST">
  Nume: <input type="text" name="nume" />
  Varsta: <input type="text" name="varsta" />
  <input type="submit" />
  </form>
</body>
</html>

Variabila $_REQUEST

Variabila $_REQUEST contine informatiile din ambele metode explicate mai ($_GET, $_POST si $_COOKIE. Discutam despre $_COOKIE la lectia despre sesiuni si cookies).

<?php
  if( $_REQUEST["nume"] || $_REQUEST["varsta"] )
  {
     echo "Salut ". $_REQUEST['nume']. "<br />";
     echo "Ai ". $_REQUEST['varsta']. " ani.";
     exit();
  }
?>
<html>
<body>
  <form action="<?php $_PHP_SELF ?>" method="POST">
  Nume: <input type="text" name="nume" />
  Varsta: <input type="text" name="varsta" />
  <input type="submit" />
  </form>
</body>
</html>

 

Programator de ~8 ani, am lucrat la proiecte din mai multe industrstrii, de la eCommerce la telecomunicatii la automatizari. In acest timp am folosi diferite tehnologii, de la PHP, MySQL, PostgreSql, RabbitMq, Redis, Memcached si altele.


Get in touch
Pentru nelamuriri, dubii, comentarii si chestii de pe suflet ne putem auzi pe Discord, Reddit sau poti deschide o discutie noua pe forum

Zprcfx # 1 month ago tricor 160mg uk <a href="https://fenoficor.com/">cheap tricor 160mg</a> tricor 200mg drug
komasin con o sin receta # 1 month ago Hi would you mind letting me know which webhost you're utilizing? I've loaded your blog in 3 different web browsers and I must say this blog loads a lot faster then most. Can you suggest a good internet hosting provider at a reasonable price? Cheers, I appreciate it!
sildenafil 100 mg en vente en ligne # 1 month ago My family members always say that I am killing my time here at net, except I know I am getting experience everyday by reading thes good articles or reviews.
Jpzkyl # 1 month ago buy generic mintop <a href="https://aminirin.com/">cheap minoxytop</a> top ed pills
Cnqgwd # 1 month ago buy acarbose medication <a href="https://tofobose.shop/">buy precose generic</a> buy griseofulvin 250mg online cheap
Mtkqun # 1 month ago buy cheap generic aspirin <a href="https://aminirin.shop/">cost aspirin 75 mg</a> order imiquimod cream
Yvrjlt # 4 weeks ago buy dipyridamole 100mg for sale <a href="https://dipyxcin.shop/">purchase dipyridamole generic</a> purchase pravastatin without prescription
Charmain # 3 weeks ago Inspiring story there. What happened after? Thanks!
Mvzmvu # 3 weeks ago cheap duphaston 10mg <a href="https://janozin.shop/">forxiga 10 mg sale</a> order jardiance online
Xuocps # 3 weeks ago order fludrocortisone 100 mcg without prescription <a href="https://pravinef.shop/">fludrocortisone online</a> order loperamide 2mg sale
Wovucg # 3 weeks ago buy etodolac pills <a href="https://colotazol.shop/">cilostazol 100mg brand</a> cilostazol 100mg generic
Xgnepx # 3 weeks ago buy prasugrel <a href="https://thoramine.shop/">buy dramamine for sale</a> tolterodine ca
albendazole a un precio asequible en Perรบ # 2 weeks ago Hi there! This article couldn't be written any better! Going through this article reminds me of my previous roommate! He constantly kept preaching about this. I will forward this article to him. Pretty sure he will have a good read. I appreciate you for sharing!
Pjtqob # 2 weeks ago ferrous sulfate 100mg for sale <a href="https://betaotec.com/">buy sotalol pills</a> cheap sotalol
Igvdbf # 2 weeks ago buy mestinon 60 mg pills <a href="https://mestien.com/">pyridostigmine 60 mg over the counter</a> maxalt 10mg us
Agrmwo # 2 weeks ago pill vasotec <a href="https://betaotec.shop/">enalapril 5mg pills</a> lactulose price
spagazer # 1 week ago <a href="https://www.sommarbutik.com/nike-air-zoom-pegasus-33-blue-runningw">nike air zoom pegasus 33 blue</a> <a href="https://www.ahealthynewu.net/christian-louboutin-black-suede-heels-louboutinno">christian louboutin black suede heels</a> <a href="https://www.workschon.com/tommy-bahama-womens-polo-shirts-polot">tommy bahama womens polo shirts</a> <a href="https://www.scifiindia.com/christian-dior-short-sleeve-button-up-polow">christian dior short sleeve button up</a> <a href="https://www.techonesolution.net/tulle-flower-girl-dresses-robept">tulle flower girl dresses</a> <a href="https://www.goldenpaisa.net/puma-muse-sneakers-blanc-sneakernl">puma muse sneakers blanc</a> [url=http://www.spagazer.com/]spagazer[/url]
Wuewnb # 1 week ago buy xalatan online <a href="https://aelimax.shop/">buy xalatan medication</a> buy exelon sale
Icloej # 1 week ago buy generic betahistine 16mg <a href="https://benedolac.com/">probalan brand</a> buy generic probenecid
Wpakwc # 1 week ago where to buy micardis without a prescription <a href="https://atizordis.shop/">buy telmisartan 80mg online</a> molnupiravir without prescription
Xnrswr # 6 days ago cenforce 50mg sale <a href="https://chlodinir.com/">aralen 250mg cost</a> buy aralen pills
Qsvgpg # 3 days ago order omnicef 300mg pills <a href="https://glurazol.com/">cheap glycomet 500mg</a> purchase lansoprazole online
Club-ul este dedicat membrilor si ofera access la mai multe zone ale website-ului.
Login Register

๐Ÿ”– Bookmarks โž•
โœจ Pentru a sustine aceasta comunitate am sa te rog sa te autentifici sau sa te inregistrezi!

๐ŸŒช๏ธ Discord โž•
Back to top
Folosim cookie-uri pentru a oferi functionalitatile critice ale aplicatiei Invata-Programare. Folosim cookie-uri si pentru a analiza traficul, pentru care e nevoie de consimtamantul dvs. explicit.