How to post parameter to remote url using php

Okay i need to create file

login.php

it will have parameter "id"

and it will post to remote url these data

http://www.designbot.com/admin.php

with following variables
and parameter "ID" retreived from login.php GET request.

RSK=83343&logger=sitelog&site=mainsite&thelogin="$Id" &thepass=passwordt&remember=on

Is there any other way to do it beside using CURL?

Can some one write me a quick sample of this.


By the way i'm using Apache 2.2.8 +  PHP 5.2.6  for windows
olivestAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

psimationCommented:
If your login.php page's function is to get the $id from your Db/script, then you can simply use :

header ("Location: http://www.designbot.com/admin.php?RSK=83343&logger=sitelog&site=mainsite&thelogin="$Id" &thepass=passwordt&remember=on");

in your script to redirect the user to that page with the GET params as you specified.
0
olivestAuthor Commented:
As i described i need POST parameters to the host not GET!
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

psimationCommented:
Once logged in, you could add a form on your page with one button, hidden formfields for all the values and form action =  "http://www.designbot.com/admin.php" and method = POST
 it's crude, but without curl, I don't know - and also, are you sure that site will accept POST's from your domain?


0
olivestAuthor Commented:
Look these are standard ways every one knows, i could use javascript for that to make it more dynamic.But i don't need that .I need PHP to process all that inside.I wonder if there is a way avoiding cURL if not,what is the quickest way to do this cycle using cURL library?
0
psadacCommented:
use streams :

http://fr2.php.net/manual/en/stream.examples.php

and see example #2 :
<?php
/* Send POST request to https://secure.example.com/form_action.php
* Include form elements named "foo" and "bar" with dummy values
*/
 
$sock = fsockopen("ssl://secure.example.com", 443, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)\n");
 
$data = "foo=" . urlencode("Value for Foo") . "&bar=" . urlencode("Value for Bar");
 
fwrite($sock, "POST /form_action.php HTTP/1.0\r\n");
fwrite($sock, "Host: secure.example.com\r\n");
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, "$data\r\n");
fwrite($sock, "\r\n");
 
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
 
echo "\n";
 
$body = "";
while (!feof($sock))
$body .= fgets($sock, 4096);
 
fclose($sock);
?>

Open in new window

0
olivestAuthor Commented:
well i get this error

Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? (24)

it looks like it doesn't support HTTP protocol only SSL or TLS.Which is no good!
0
EgonFreemanCommented:
Instead of using fsockopen() which uses handler streams, try creating a socket with socket_create() and then use socket_connect().

The socket would have to be created like this:

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // type STREAM, TCP

then

socket_connect($sock, "secure.example.com", 443);

it bypasses handlers, as everything is done in raw communication (am I wrong here?). Of course, then for reading and writing You have to use socket_read() and socket_write() - but that's all in the PHP manual.

Retrieving the error can be done through socket_last_error() [returns an INT], and then passing the int through socket_strerror().

The rest would be done pretty much as psadac described it, although You would have to handle the certification and everything else associated with SSL... ;-)
0
olivestAuthor Commented:
Does it works with HTTP protocol or only SSL?.How can i print output of remote page HTML response?
0
psadacCommented:
i just slightly modified the previous example to handle http and outputed the response headers and the content :
<?php
/* Send POST request to http://www.example.com/form_action.php
* Include form elements named "foo" and "bar" with dummy values
*/
 
$host = 'www.example.com';
$url = '/form_action.php';
 
$sock = fsockopen($host, 80, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)\n");
 
$data = "foo=" . urlencode("Value for Foo") . "&bar=" . urlencode("Value for Bar");
 
fwrite($sock, "POST $url HTTP/1.0\r\n");
fwrite($sock, "Host: $host\r\n");
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, "$data\r\n");
fwrite($sock, "\r\n");
 
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
  
$body = "";
while (!feof($sock))
$body .= fgets($sock, 4096);
 
fclose($sock);
 
echo nl2br($headers), $body;
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
olivestAuthor Commented:
excellent that what i was looking for
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.