Jump to content

fget/fput question


doni49

Recommended Posts

I have dealt with fgets/fputs for retrieving data off of ONE page.  I've also been familiarizing myself with regular expressions (preg_match_all) so that I can parse the data.

However, in this case I'm not too sure how to approach this project.  I need to have a script that will perform the following steps:

[list]
[*]Visit a URL
[*]On the resulting page, fill in a text field and submit the form
[*]On the next page, fill in three fields and submit the form
[*]On the next page, retrieve data from the page
[*]depending upon the content of the data on this page, submit the form again (doing so brings up the next page of data)--keep doing so until the page says "End of File" which I'll be able to find ith preg_match_all
[/list]

What's got me stumped are two issues:  how to simulate pressing the submit button and how to simulate pressing the submit button ONLY if I haven't already retrieved all the data.  I'm still in the planning stage so I don't really have any code yet, but in PLANNING it, I see these two issues.

THANKS a bunch!
Link to comment
https://forums.phpfreaks.com/topic/27738-fgetfput-question/
Share on other sites

I tried the following code.  All that I get is a BLANK page in my browser.
[code]
<?php
  $ch = curl_init();
  curl_setopt($ch,CURL_URL, "http://4.43.65.248/autoform.asp?app=cvr");
  curl_setopt($ch, CURLOPT_COOKIEFILE, "/curl-cookies/cookie.txt");
  curl_setopt($ch, CURLOPT_COOKIEJAR, "/curl-cookies/cookie.txt");
  curl_setopt($ch, CURLOPT_HEADER, TRUE);
  curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  $txt = curl_exec($ch);
  curl_close($ch);
  echo $txt;
?>
[/code]

On the first page (what I expected this to return), I don't have any fields to post.

PHPInfo shows the following:
[quote]
[size=14pt][b]curl[/b][/size]
CURL support enabled
CURL Information libcurl/7.15.3 OpenSSL/0.9.7a zlib/1.2.3
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/27738-fgetfput-question/#findComment-126928
Share on other sites

Your not returning anything because you don't have that option set!


[code]<?php

$url = 'http://4.43.65.248/autoform.asp?app=cvr';

$jar = '/curl-cookies/cookie.txt';

$io = curl_init ();

// the url to fetch, string (uri)

curl_setopt ( $io, CURLOPT_URL, $url );

// ? return the response header (0 = no, 1 yes)

curl_setopt ( $io, CURLOPT_HEADER, 0 );

// ? the connection time out (int)

curl_setopt ( $io, CURLOPT_TIMEOUT, 5 );

// ? expect [chunck, gzip] transfers (empty str)

curl_setopt ( $io, CURLOPT_ENCODING, '' );

// ? maximum redirect(s) to follow (int)

curl_setopt ( $io, CURLOPT_MAXREDIRS, 1 );

// ? where to save [Set-Cookie] (str, path + file name)

curl_setopt ( $io, CURLOPT_COOKIEJAR, $jar );

// ? where to read and send [Cookie] (str, path + file name)

curl_setopt ( $io, CURLOPT_COOKIEFILE, $jar );

// ? follow location headers (0 = no, 1 = yes)

curl_setopt ( $io, CURLOPT_FOLLOWLOCATION, 1 );

// ? return data to curl_exec(), (0 = no, 1 = yes)

curl_setopt ( $io, CURLOPT_RETURNTRANSFER, 1 );

// the user agent

curl_setopt ( $io, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)' );

// execute the request

$page = trim ( curl_exec ( $io ) );

// release the resource

curl_close ( $io );

echo $page;

?>[/code]



printf
Link to comment
https://forums.phpfreaks.com/topic/27738-fgetfput-question/#findComment-126955
Share on other sites

Thanks for the help.  I found return transfer after I posted that last bit of code.  So I modified my post to reflect what I was trying.  What I WAS trying (which is posted above) didn't work.  But you posted at the same time as I saved my modification of the post.

I tried your code and it got the job done.
Link to comment
https://forums.phpfreaks.com/topic/27738-fgetfput-question/#findComment-126965
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.