954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How can I send variables from a PHP script to another URL using POST without.........

Hi!!
Please guide me. How can I send variables from a PHP script to another URL using POST without using forms and hidden variables?

Thanks
Laxy

laxy_m
Newbie Poster
10 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

I don't think you can, I can't remember if you could do this off the top of my head; tell us what exactly you are trying to do instead of being so general.

Gary King
PHP/vBulletin Guru
Team Colleague
417 posts since Nov 2003
Reputation Points: 53
Solved Threads: 5
 

ok thanks i will try it.

Regards
Laxy

laxy_m
Newbie Poster
10 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

Have u got solution for this.

vijiruba
Newbie Poster
2 posts since Apr 2006
Reputation Points: 10
Solved Threads: 0
 

You can do it with javascript, here a good article with the basics:
http://www.w3schools.com/dom/dom_http.asp

Basically you can create an HTTP request from within your page and get back and process a responce.

I guess this could be possible in PHP also. I have a look into it.

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

Here you go check this out:

http://uk.php.net/curl

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

You can open an HTTP socket connection and send HTTP POST commands. Here is
an example :

<?
// Generate the request header
$ReqHeader =
"POST $URI HTTP/1.1\n".
"Host: $Host\n".
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $ContentLength\n\n".
"$ReqBody\n";

// Open the connection to the host
$socket = fsockopen($Host, 80, &$errno, &$errstr);
if (!$socket)

$Result["errno"] = $errno;
$Result["errstr"] = $errstr;
return $Result;
}
$idx = 0;
fputs($socket, $ReqHeader);
while (!feof($socket))

$Result[$idx++] = fgets($socket, 128);
}
//-------------------------------------------
?>

Or you can use the cURL extensions for PHP ( http://curl.haxx.se ). Once you build it and compile their support into PHP, it is fairly easy to do posting stuff (even over https):


<?
$URL="www.mysite.com/test.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "Data1=blah&Data2=blah");curl_exec ($ch);
curl_close ($ch);
?>

This will have the net effect of posting your data to the $URL site, without any header hacking.

You can also do other nifty things with cURL, like retrieve the HTML into variables and scrape through it for neat functionality.

To use cURL you need to recompile PHP or check with your ISP to see if they support it ( http://www.php4hosting.com does)

manishMCAIT
Newbie Poster
6 posts since Jun 2006
Reputation Points: 11
Solved Threads: 0
 

If you are posting within your own server, you may not need to connect to the host as shown by manishMCAIT.

zippee
Posting Whiz in Training
294 posts since Jan 2005
Reputation Points: 10
Solved Threads: 7
 

Hi Lexy M, I have checked this site, they are doing some cool work on PHP:) also there article collection is strong...check it on www.webdesigningcompany.net/articles.php

Bryan McPherson
Newbie Poster
2 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You