PDA

View Full Version : Sending Headers


DirectPixel
Fri 14th Jun '02, 11:20pm
How would I go about getting a PHP page to send headers to another page?

For example, I want a PHP script to auto-submit information that's usually in a form field to its destination, and then redirect the user to that page's output. Can this be done?

The Prohacker
Sat 15th Jun '02, 12:46am
<?
header('Location: 'http://www.domain.com/form.php?id=$id');
?>

Something like that???

You'd have to know what info the script takes in, and set the varibles accordingly...

DirectPixel
Sat 15th Jun '02, 12:48am
I'm basically trying to code the purchase page for my site at www.eisecure.com

Basically, the drop-down list info is sent to a PHP file, which right now, just redirects (using the header(location:) code) to the appropriate PayPal page.

However, because it's just a redirect, the price, name, etc. are all in the URL, so the user can modify it.

What I'm asking is how I would go about sending the info directly to the PayPal processor, without having all the info in the URL.

Thanks,
Alex

The Prohacker
Sat 15th Jun '02, 12:53am
Ah well...

Thats a normal problem with paypal.... And not very many solutions to do anything about...

DirectPixel
Sat 15th Jun '02, 12:56am
Well, I think there's a way to do it, or how else do PHP scripts communicate with each other (other than cookies and session variables).

The Prohacker
Sat 15th Jun '02, 12:57am
Hmmm.... What about your form? Are you using GET or POST?

DirectPixel
Sat 15th Jun '02, 12:57am
POST.

Gramphos
Sat 15th Jun '02, 6:36pm
So, you convert it from POST to GET?

You could probably send it directly as a post, but then you would have to deal with the response and show it for the user.
$buffer is the data to post.

$host='www.example.com';
$fp=fsockopen($host,80,$errno, $errstr, 30);
if ($fp){
echo $errstr."(".$errno.")";
}
fputs($fp, POST $document HTTP/1.1\nHost: $host\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-Length: ".strlen($buffer));
fputs($fp, "Connection: close\n\n");
fputs($fp, $buffer);

$page_result='';
while (!feof($fp))
$page_result.= fgets($fp,128);
fclose($fp);
if (!stristr($page_result,"<base")){
$page_result=preg_replace("#((SRC|HREF)="?)(/.*?("|\s))#","$1$host$3",$page_result);
}
print $page_result;

Note, I've not tested this, and I'm a little unsure about if the later part (which is supposed to add $host to the beginning of releative urls if no <base is found) wll work. I've done it before, but it was some time before. However, I hope you get the idea.

DirectPixel
Sat 15th Jun '02, 6:38pm
Okay, I think I have somewhere to start with now... thanks!:)

Gramphos
Sat 15th Jun '02, 7:30pm
Hope you see that I missed a double qoute (") bofore POST and a backslash before the n (after $host)

DirectPixel
Sat 15th Jun '02, 7:38pm
Originally posted by Gramphos
Hope you see that I missed a double qoute (") bofore POST and a backslash before the n (after $host) Yeah, I saw those after PHP gave me an error.;)

Gramphos
Sat 15th Jun '02, 9:51pm
And as you are dealing with forms here maybe ACTION should be among HREF and SRC.

Or you could add a basetag in the header. I think that is easier. Has long as it has a <HEAD> tag that is.

Chen
Sun 16th Jun '02, 2:42am
You can also use Curl, http://php.fastmirror.com/manual/en/ref.curl.php.

DirectPixel
Sun 16th Jun '02, 1:33pm
Originally posted by FireFly
You can also use Curl, http://php.fastmirror.com/manual/en/ref.curl.php. The problem with that is my webhost doesn't seem to have PHP compiled with CURL...