Jump to content

POST in PHP

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
falco85

falco85

    Programmer

  • Members
  • PipPipPipPip
  • 105 posts
I've tried again and again but I can't get it to work. How can I POST data from my PHP script and retrieve the results??

#2
Thomas

Thomas

    Newbie

  • Members
  • PipPip
  • 15 posts
Hi Falco,

Can you tell me if your trying to POST to another HOST or if your using a FORM and want to display the results of the entered fields?

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Yes, if you are trying to post using a FORM it is a little different than if you are posting to another host. Form post, as you may know, is simply HTML:

<form action="postscript.php" method="POST">

Here is how you POST to a form using [ CURL ] on another host:

<?
$url="http://anything";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "fieldname=fieldvalue&fieldname=fieldvalue&");
#curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$content = curl_exec ($ch); # This returns HTML
curl_close ($ch);
?>

To get the page only using the URL (no POST data):

<?
$url="http://anything";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$xml = curl_exec ($ch);
curl_close ($ch);

?>


#4
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
Some places do not let you post like Google. You had better check the TOS of the sites you want to post/retrieve from.

#5
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
also depending on your registred global settings you may have to use $_POST['variable'] on the page you are posting to.