simple html post-get (noob question)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasonhoblin
Forum Newbie
Posts: 1
Joined: Sat Jan 11, 2014 12:39 pm

simple html post-get (noob question)

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: simple html post-get (noob question)

Post 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).
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply