Page 1 of 1

simple html post-get (noob question)

Posted: Sat Jan 11, 2014 12:58 pm
by jasonhoblin
i'm looking for a snippet of code in php to post a set of variables to a url and then display the return data. example:

&field1=a&field2=b&field3=3
https://www.example.com/dir/

i searched for a few hours and cannot put the code together. most of the php sites talk about post and get functions, but i cannot find a good, rather working, example. i am going to create forms on the page to gather vars and then build and post the url. i think... the server i am posting to will process the vars and return a big string of data. i confident i can parse the data. thanks in advance!

do i need two php pages, one to call the other? do i use html form submit? what tells the page to just display/print the response.

Re: simple html post-get (noob question)

Posted: Sat Jan 11, 2014 1:25 pm
by social_experiment
posting.php?mode=reply&f=1&t=139032
^ this is an example of $_GET; values passed along in a query string i.e mode=reply&f=1&t=139032
The values will be available in the $_GET superglobal variable as

Code: Select all

$_GET['mode'] = 'reply'
$_GET['f'] = '1'
$_GET['t'] = '139032'
$_POST is more often used form form submissions and the data isn't passed along in the query string;

Code: Select all

<?php
 $a = 'John';
 $b = '25';
 $c = 'Seven';

 echo '<a href="page.php?a=' . $a . '&b= ' . $b . '&c= ' . $c . '" >Go</a>';

 // when clicked goes to page.php?a=John&b=25&c=Seven 

?>
Passing data in the query string means it can be easily manipulated so have a look at urlencode() and check any data that you receive from the user (either from POST of GET).