SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Sending POST data with fopen
-
Jun 23, 2007, 08:20 #1
- Join Date
- Jun 2006
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sending POST data with fopen
I have been stuck on this for hours and hours, hoping someone here can help.
I am trying to access another web page using fopen, but that web page requires POST data (I tried www.domain.com/page.php?param=1) and it won't work, so I am forced to do a POST.
I can't use CURL because my PHP Version is 4.3.x.
Can someone advise please?
Thanks.
-
Jun 23, 2007, 08:29 #2
- Join Date
- Jun 2006
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
by the way, the script I am trying to pass data to is not mine and it's on another server.
-
Jun 23, 2007, 08:30 #3
-
Jun 23, 2007, 08:39 #4
- Join Date
- Jun 2006
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I found 2 different scripts online and they both sort of worked but not completely.
PHP Code:<?php
# $host includes host and path and filename
# ex: "myserver.com/this/is/path/to/file.php"
# $query is the POST query data
# ex: "a=thisstring&number=46&string=thatstring
# $others is any extra headers you want to send
# ex: "Accept-Encoding: compress, gzip\r\n"
function post($host,$query,$others=''){
$path=explode('/',$host);
$host=$path[0];
unset($path[0]);
$path='/'.(implode('/',$path));
$post="POST $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\n${others}User-Agent: Mozilla 4.0\r\nContent-length: ".strlen($query)."\r\nConnection: close\r\n\r\n$query";
$h=fsockopen($host,80);
fwrite($h,$post);
for($a=0,$r='';!$a;){
$b=fread($h,8192);
$r.=$b;
$a=(($b=='')?1:0);
}
fclose($h);
return $r;
}
echo post("www.domain.org/page.php","param=1");
?>
Here is a piece of the result with the weird letters/numbers in it:
15
<option value='blah'
f
>blah</option>
14
<option value='blah2'
e
>blah2</option>
13
<option value='blah3'
d
>blah3</option>
15
<option value='blah4'
f
>blah4</option>
18
The things in bold aren't supposed to be there and I don't see them when I try to access the page through browsers, only when I do it with the script.
so confused....
-
Jun 23, 2007, 08:52 #5
- Join Date
- Jun 2004
- Location
- United States
- Posts
- 811
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Why not have a form directly post to the other file on the other server like normal?
Founder/Admin of a pretty decent chat forum
Download free winterboard themes for your iPhone
I run sites powered by vbulletin and one about the HTC Jetstream.
-
Jun 23, 2007, 08:55 #6
- Join Date
- Jun 2006
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I need the data that the destination site returns as I need to do additional work to that data.
-
Jun 23, 2007, 09:21 #7
- Join Date
- Mar 2005
- Location
- Ukraine
- Posts
- 1,403
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does website return any non-Latin letters?
-
Jun 23, 2007, 10:05 #8
- Join Date
- Jun 2006
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks