473,382 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Passing Post variables using fopen()

I'm trying to pull data from a website and read it into a file the I
can parse. I've done the before to site without post variables but I
can seem to get my statments to work with the post. Can someone help
me out?
below is the code I have so far. Thank in advance...

$url="www.somesitethatneedspostvariables.com";

$postdata = http_build_query(
array( 'postvarname1' ='value1',
'postvarname2' ='value2'
)
);
$opts = array('http' =>
array(
'method' ='POST',
'header' ='Content-type: application/x-www-form-
urlencoded',
'content' =$postdata
)
);

$context = stream_context_create($opts);
$file = @fopen($url, "r", $content) or die("Connection Error, Please
contact Webmaster ERROR CODE=0xDEADBEEF");

Mar 21 '07 #1
2 8079
Aa***@flasemi.com wrote:
I'm trying to pull data from a website and read it into a file the I
can parse. I've done the before to site without post variables but I
can seem to get my statments to work with the post. Can someone help
me out?
below is the code I have so far. Thank in advance...
Hi,

www.php.net/curl might be just what you are looking for. ;-)

Regards,
Erwin Moller
>
$url="www.somesitethatneedspostvariables.com";

$postdata = http_build_query(
array( 'postvarname1' ='value1',
'postvarname2' ='value2'
)
);
$opts = array('http' =>
array(
'method' ='POST',
'header' ='Content-type: application/x-www-form-
urlencoded',
'content' =$postdata
)
);

$context = stream_context_create($opts);
$file = @fopen($url, "r", $content) or die("Connection Error, Please
contact Webmaster ERROR CODE=0xDEADBEEF");
Mar 21 '07 #2
On Mar 21, 12:42 pm, A...@flasemi.com wrote:
I'm trying to pull data from a website and read it into a file the I
can parse. I've done the before to site without post variables but I
can seem to get my statments to work with the post. Can someone help
me out?
below is the code I have so far. Thank in advance...
Here's some code I've used for this... change the port default to 80
if you don't work over SSL... original version of this code was copied
from somewhere, I forget where:

function HTTPS_Post($URL, $dat, $referrer="")
{
// parsing the given URL
$URL_Info=parse_url($URL);

// Building referrer
if($referrer=="") // if not given use this script as referrer
$referrer=$_SERVER["SCRIPT_URI"];

// making string from $data
foreach($dat as $key=>$value) $values[]="$key=".urlencode($value);
$data_string=implode("&",$values);

// Find out which port is needed - if not given use standard (=443)
if(!isset($URL_Info["port"])) $URL_Info["port"] = 443;

// building POST-request:
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n";

$result = '';
if ($fp = fsockopen("ssl://" . $URL_Info["host"], $URL_Info["port"],
$errno, $errstr, 2.0))
{
fputs($fp, $request);
$started = time;
while((!feof($fp)) and ((time - $started) < 5))
{
$result .= @fgets($fp, 128);
}
fclose($fp);
}
return $result;
}

Mar 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** HI, I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text,...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage...
6
by: Andreas Thiele | last post by:
Hi, I'm very new to php. In my current code I'd like to bind variables to the values of a simply (only indexed by numbers http://www.php-center.de/en-html-manual/language.types.array.html])...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
7
by: Khai | last post by:
First off, yes, I understand the crapload of tutorials out there, (well, rather, I understand there /are/ a crapload of tutorials out there), the problem is my comprehension. I'm trying to pass...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
5
Atli
by: Atli | last post by:
Hi everybody. After years of C# and PHP, I'm finally returning to Java. My goal is to create a Java program capable of sending images to a PHP Photo Album on my web server. Right now, however,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.