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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying everything 1

Status
Not open for further replies.

Netwrkengeer

IS-IT--Management
Apr 4, 2001
184
US
Ok I'm very new at this stuff, but I keep running through different commands and nothing is working. here is some code I wrote, the first piece is the html which is working fine. The second 2 pieces are 2 separate attempts to achieve my desired result.

My desired result is to send info to a website, and grab the raw html of the site.

/*HTML,eagle5.htm works fine*/
<html><head><title>SM2</title></head><body>
<!--the form attempts to send info via &quot;POST&quot; locally to sm2proc2.phtml-->
<FONT FACE=&quot;DAXLIGHT&quot; >
<TABLE COLSPEC=&quot;L20 L20&quot; >
<TR>
<TD>
<H1>
</H1>
</TD>
<TD>
Input your address.&nbsp;
<FORM ACTION=&quot;sm2proc2.phtml&quot; METHOD=post>
<PRE>
<!--the form variables street,city,state,zip, are unalterable-->
Street Address: <INPUT SIZE=30 NAME=&quot;street&quot;>
City: <INPUT SIZE=30 NAME=&quot;city&quot;>
State: <INPUT SIZE=3 NAME=&quot;state&quot;> Zip: <INPUT SIZE=6 NAME=&quot;zip&quot; <br>

<input type=submit name=&quot;geocode&quot; VALUE=&quot;request&quot;>
</PRE>
</FORM>
</TD>
</TR>
</TABLE>

</body></html>


/*PHP1, problem, won't echo/print contents of html from url, I test the url variables with echo and it printed the url with the inputed variables correctly, I then copied the correctly echo url into the address bar of my browser, and it gave me the page I wanted to see, so it works the way I want it to. now for the problem, with this code I get a log in page, not what I want.*/
<?php
/*
overview of code.
To submit info to a website via its URL, utilize variables from the POST form eagle5 which are concated into the url.
*/

readfile(&quot;
exit();

?>


/*PHP2, problem, won't echo/print contents of html from url, I test the url variables with echo and it printed the url with the inputed variables correctly, I then copied the correctly echo url into the address bar of my browser, and it gave me the page I wanted to see, so it works the way I want it to. now for the problem, with this code I get an echo of (0), not what I want.*/

<?php
/*
overview of code.
To submit info to a website via its URL, utilize variables from the POST form eagle5.htm which are concated into the url.
*/

/*opening connection to site, utilizing variables to access activated part of site i.e. $street*/
$fp = fsockopen (&quot; 80, $errno, $errstr, 30);
if (!$fp) {
echo &quot;$errstr ($errno)<br>\n&quot;;
} else {
fputs ($fp, &quot;GET / HTTP/1.0\r\n\r\n&quot;);
while (!feof($fp)) {
echo fgets ($fp,128);
}
fpassthru ($fp);
}

?>

/*PHPtest, this is the code I used to test the form and url.*/

<?php
echo $street.&quot;<br>&quot;;
echo $city.&quot;<br>&quot;;
echo $state.&quot;<br>&quot;;
echo $zip.&quot;<br>&quot;;
echo &quot; 80, $errno, $errstr, 30;
?>

I'm stumped,
thanks for any help you can give.
robert
 
rycamor is correct and is the very typical way to do things and the way I always do it (laziness is the key).

In these forums, I usually try to provide code that is instructive and get posters to understand their code and provide the 'standard' method to achieve their results.

In any case, $fc = @file($filename); echo $fc[103].... works just fine. Just remember, you should ALWAYS check for the existence of the line first, so you can either use my method or rycamor's method (which ends up taking as much coding) of if(isset(...)) {....}

Also remember that neither of our examples check for the validity of the line even if it exists such that the output will be what you expect...what happens if the geocode decides to modify their code somewhat and make it spit out, say, random content at a certain location with random numbers of lines? OOPS! You've got yourself a big problem. That is where regexps come in and that is what you should really be using.


Chad. ICQ: 54380631
online.dll
 
True, true...

Whenever I am doing something like this (grabbing remote data from a page), Rather than rely on the line number, I try to identify anything distinctive in the HTML that will assure me of finding the right data, even if the line numbers shift. In this case, it looks like Geocode isn't being too helpful, as the HTML is very standard, with no extra identifiers or custom tags. However it wouldn't be too difficult--for example-- to extract only the contents of the first HTML table, or the second one, and then do further manipulations with that subset, if necessary.

I imagine, though, that if you are purchasing the Geocode service in the future, they probably have other ways of delivering the data, such as XML, or comma-separated values, or some such...(?)
 
Actually, they have a client that you download.

I downloaded it and tried it and it returns data in <data>\n responses (not xml, but more of just a formated response).

The client itself really stinks and has some bugs.

Basically, you do ./rie -a [address delim by |] -u [username] -p [pass]

[username] and [pass] default to guest

The problem is the -a argument passed into rie. For some reason it does not recognize the value passed and believes you have not entered anything there. It then provides a prompt where you have to enter in the address information AGAIN.

I have the source and am currently rewriting it so that it will correctly read in the arguments (written in C).

Chad. ICQ: 54380631
online.dll
 
Thank you very much, you guy's are amazing, I'm very impressed.

now let me ask you, does the connection to the server stay open, do I need to close the connection,
should I use
die ()
or exit ()
or escapeshellcmd ()
as if I knew how to use them.
Anyway, thanks
and Chad if you fix that code I'd like to see it.
and if you have the time to send me the curl binaries that would be cool too.
Netwrkengeer@aol.com
 
Theoretically

When it comes to HTTP connections, you don't really have to worry about closing connections, except for some special cases. It's theoretically good practice to get in this habit, though, because you might forget to close if you are opening an FTP connection, or some other protocol.

With PHP, most of the functions that access external URLs, such as the file() or include() functions, handle this for you. The only time when you might want to explicitly fclose() a connection is when you explicitly open one with fsockopen(). Again, not crucial when you are using HTTP connections, but oherwise, good practice.
 
Netwrkengeer,

I have archived my copy of curl for you to use.


NOTE:

There is no guarantee that this will work on your machine, but chances are it will as long as you don't have some kind of wierd configuration for your box.

It is extremely easy to use and fast.

Chanes are, you don't have curl support in PHP, so all you have to do is use popen() or exec() or shell_exec() to make a call directly to the binary with parameters.

$response = shell_exec(&quot;./my/abs/path/to/curl/bin/curl --dump-header headers.txt $filename&quot;);

There are too many features and options for curl to list here, but I use --dump-header headers.txt for debugging purposes (it spits the header information returned from the requested url and stores it in this file).

Chad. ICQ: 54380631
online.dll
 
Oh yeah, I forgot....

This binary of curl I provided for download, is already compiled for SSL support so you can use instead of http:// (don't need https:// unless you are doing financial transactions, etc. so I would not recommend it for this specific application).

Chad. ICQ: 54380631
online.dll
 
Thank you. If I have more questions, I'll start another thread.
Talk to you later
Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top