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

Access to html content throught php script

Status
Not open for further replies.

egmweb

Programmer
Mar 19, 2004
147
EU
Hello all.

I need to make an script that takes information from other website and publish into my website.

For example.

I have my own website, and I need to give to my customers the total of bandwith used. And this information is in other website that provide me the bandwith total for each customer.

Thanks you.
 
Assuming you are not violating any copyright, access policies etc.:
There are several moethofs to retrieve remote HTML content. ALl of them have in common that they send a HTTP GET request for the page.
-> file_get_contents() PHP 4.3 and up with URL wrappers enabled
-> socket connections with fsockopen and a manually creafted HTTP request
-> cURL functions

These are some basic methods. Read about them, and you'll see that it is not so difficult.
 
Thanks. Yes, of course, I'm not violating any policy or copyright...

Please would you be more especific?... I'm new in this php world.

Thanks you.
 
I'd say the easiest way is file_fet_contents(). However, for URLs the appropriate wrappers have to be enabled.
Check the output from phpinfo() and see if it says '--disable-fopen-url-wrapper' and check the setting in the php.ini:
Again, you need PHP 4.3.0 or later.
Best is if you have 4.3.10 or 5.0.2 given the latest security issues (especially if run on IBM based platforms).
Code:
<?
$content = file_get_contents("[URL unfurl="true"]http://www.whatever.com/mypage.html");[/URL]
?>
This will put the page into a string which you then are able to manipulate, extract parts etc.
 
Thanks for your help, but I couldn't understand what you saying.
 
What version of PHP do you run?
Check that out with a little script like:
Code:
<?php
phpinfo();
?>
We'll go from there.
 
Hi, DRJ478. Thanks for your patience.

I'm Using PHP Version 4.3.5
 
All right, that's good news. Now let's see if you can open a page using file_get_contents():
Code:
<?php
$content = file_get_contents("[URL unfurl="true"]http://www.cnn.com/");[/URL]
echo $content;
?>
This should bring up the CNN home page - or produce an error message if the fopen URL wrappers are disabled.
 
Hi, DRJ478.

Yes, Yes, It's returned me the cnn home page!!
 
Hi DRJ478, But how can extract some content (text)of this website?
 
Now the question is how to identify the portion of the HTML that you want to extract. Is it in a specific table? Does it start with a specific text?
The job now is to find the non-changing structure so we can devise a way to just extract the portions we want to turn into vars.
Bring up such a page in your browser and save the HTML source. Inspect it and find out the portions that we need to extract. Maybe you can save the HTML page somewhere and post a link.
 
Yes, Sure...

I provide Webhosting. I'm making my website. I have an external website from my hosting provider, where I can control the bandwith of my customers. I have to login in and I have this information.

Then, at my ouw website, I need that my customers has the option to see their bandwith %.

Would you please send me your email personal address to give you the login and password of the site?

Thanks you.
 
I'll respond to you in the morning. I've seen tha page and think it is fairly easy to extract the desired data.
 
DRJ478:
after looking at that source-code, I think we should know if the user has the same account-name on the server which is fetching the content. If not, it should search for domain instead?

if the admin on the other server could add some html comments, I guess it could be easier to match for pattern.

<!--#c_start-->
<!--#c_stop-->

or maybe he could add some
<input type="hidden" name="username" value="foo" />
<input type="hidden" name="bandwidth" value="600Tb" />

Olav Alexander Mjelde
Admin & Webmaster
 
Are you sure you are not reinventing the wheel here?

If you have a hosting account that lets you sell subhosting (as in a reseller account) then normally there are specific control panels available for your customers. They can log into a control panel similar to your own and see all the info they need to know about their account.

Of course, if you have rented a dedicated server of some kind then things may be different. Are you using some kind of control panel like Plesk (for example)?

- Web design and ranting
- Day of Defeat gaming community
"I'm making time
 
you know you can just use readfile() now days for urls even.

for example on my own website I could put

Code:
<?
readfile("[URL unfurl="true"]http://www.cnn.com");[/URL]
?>

and it would show the content of cnn on my site.

Karl Blessing
PHP/MySQL Developer
 
To finish the suggestions:
I think since the page has all values within a table that has a specific structure a regular expression will be able to extract the desired values.
Foamcow has a good point, if there's a Control Panel it should have the bandwith displayed. However, I'll entertain your try for a customized solution.
Code:
<?
# I assume the page is loaded into $text
$pattern = "/<tr[^>]*>\s*<td>(\w*)<\/td>\s*<td>([^<]*)<\/td>\s*<td[^>]*>([^<]*)<\/td>\s*<td[^>]*>.*\s*<td[^>]*>([^<]*)<\/td>/";
preg_match_all($pattern,$text,$myArr);
foreach($myArr[1] as $key=>$value){
	$hostStat[$value]['name'] = $myArr[2][$key];
	$hostStat[$value]['used'] = $myArr[3][$key];
	$hostStat[$value]['allow'] = $myArr[4][$key];
}
print_r($hostStat);
?>
 
Hello all. Thanks you Very much Guys for your Interest, I will try this code and I will let you know if it results succeed.

Thanks you.

Eduardo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top