•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,212 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,747 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 12992 | Replies: 8
![]() |
•
•
Join Date: Sep 2004
Posts: 10
Reputation:
Rep Power: 4
Solved Threads: 0
How can I send variables from a PHP script to another URL using POST without.........
#1
Sep 28th, 2004
•
•
Join Date: Nov 2003
Location: Toronto, Canada
Posts: 354
Reputation:
Rep Power: 6
Solved Threads: 5
Re: How can I send variables from a PHP script to another URL using POST without.........
#2
Sep 28th, 2004
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.
•
•
Join Date: Sep 2004
Posts: 10
Reputation:
Rep Power: 4
Solved Threads: 0
Re: How can I send variables from a PHP script to another URL using POST without.........
#3
Oct 6th, 2004
•
•
Join Date: Apr 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Re: How can I send variables from a PHP script to another URL using POST without.....
#4
Apr 4th, 2006
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation:
Rep Power: 7
Solved Threads: 59
Re: How can I send variables from a PHP script to another URL using POST without.....
#5
Apr 4th, 2006
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.
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.
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation:
Rep Power: 7
Solved Threads: 59
Re: How can I send variables from a PHP script to another URL using POST without.....
#6
Apr 4th, 2006
•
•
Join Date: Jun 2006
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
Re: How can I send variables from a PHP script to another URL using POST without.....
#7
Jul 10th, 2006
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)
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)
•
•
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation:
Rep Power: 4
Solved Threads: 6
Re: How can I send variables from a PHP script to another URL using POST without.....
#8
Jul 10th, 2006
If you are posting within your own server, you may not need to connect to the host as shown by manishMCAIT.
Ecommerce-Web-Store.com Building Your e-Business.
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Re: How can I send variables from a PHP script to another URL using POST without.....
#9
Nov 30th, 2006
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
also there article collection is strong...check it on www.webdesigningcompany.net/articles.php ![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Create double blind system in php (PHP)
- cPanel: email account creation. I need help making a PHP script. (PHP)
- PHP Script (PHP)
- IP-to-Country converter (php script) (PHP)
- PHP Script Translate To VB 6.0 (Visual Basic 4 / 5 / 6)
- question about connecting odbc to sql through php script (PHP)
Other Threads in the PHP Forum
- Previous Thread: Password protection for Website
- Next Thread: Problem



Linear Mode