Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there anyway to pass POST variables to a site with Header()?

Status
Not open for further replies.

748323

Programmer
Dec 10, 2004
70
US
I'm getting pretty good at PHP, and I was just wondering, when I use Header("Location: "), I can pass GET variables through the URL. Is there anyway I can pass POST variables do the page? Thanks.
 
Yes, there is.
You need to study the HTTP headers documentation. It explains how to write the correct headers.
You could also use the cURL functions, if your PHP was compiled with them. Have a look at your phpinfo() output.
CURL:
 
I have cURL installed. I was going to ask about that, but I wasn't sure.

How would I use cURL do to it? I know to set set up and use cURL, just not that function.

I'm assuming you do something like:

$postvars = 'user=scorpion&pass=' . $pass;
curl_setopt($curl, CURLOPT_POST, $postvars);

Mind correcting that a bit? Thanks.
 
Now, having thought a bit about this:
cURL will POST something to a script, but it will not send your browser there.
But to give an example:
Code:
<?php

$ch = curl_init();
$res= curl_setopt ($ch, CURLOPT_URL,"[URL unfurl="true"]https://yoururl/cgi");[/URL]

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "Idc=si&");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$xyz = curl_exec ($ch);

curl_close ($ch);

You still can write the headers yourself or use parts of the HTTP classes in PEAR. The RFC 2616 (HTTP) talks about how the headers have to look.
 
Wait.. cURL will run the script, but not send my browser there? That's awesome! That's exactly what I wanted.

I'll give that a try.

Kind of like inet functions of VB, except it doesn't depend on IE. Thanks!
 
Thanks a lot. My script worked perfectly. It connects to a specific message board, grabs the last message that was posted, and changes my signature on that forum according to the last message.

Since it doesn't redirect the browser, I used FireFox' reload every to make it do it every 15 seconds. Hopefully the admin doesn't care. Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top