Page 1 of 1
Opening website source over https
Posted: Mon May 02, 2005 10:10 am
by smashy
Hi everyone,
I am attempting to grab the source of a website so that I can strip out information that I don't want and only display a subset to the user.
The problem I am having is with actually getting the contents of the file. I am used to using methods like file('filename') or fopen('filename') and whatnot (which works in normal cases).
I think the issue is that the page I want to open is at:
https://"some host address here"/cgi-bin/status.cgi?hostgroup=all&style=summary
I guess that the https protocal and the cgi source is causing the problem.
Any pointers on how to access this source so that I can manipulate the way it appears on screen? Code examples would be very helpful. Ideally, I would like an array of the source file like file('filename') would give me, but beggers can't be choosers.
Thanks.
Posted: Mon May 02, 2005 12:58 pm
by shiznatix
maybe try file_get_contents(); ....or post some code so we can see were your going wrong maybe
Posted: Mon May 02, 2005 1:10 pm
by smashy
There really isn't much to post since I am not contining unless I can get the source for the page I am trying to access.
Here is the code I was using to see if I could access it.
Code: Select all
<?
//open the file
$f = fopen("https://dev.cygnalcare.ca:20020/nagios/cgi-bin/status.cgi?hostgroup=all&style=summary", 'r');
//put the lines into an array
$fcontents = file($f);
//try printing
echo $fcontents[1];
//try printing
echo $fcontents[0];
//close the file
fclose($f);
?>
Thanks for any help.
Posted: Mon May 02, 2005 2:18 pm
by shiznatix
well 1st off you dont need to open the file to use file on it. why dont u try doing
Code: Select all
$arr = file ("https://dev.cygnalcare.ca:20020/nagios/cgi-bin/status.cgi?hostgroup=all&style=summary");
foreach ($arr as $key => $value)
{
echo 'Line '.$key.' containes '.$value.'<br>';
}
but your probebly want to use htmlentities so you can view the source of the page.
Posted: Mon May 02, 2005 3:17 pm
by smashy
Running the above code (thanks by the way) I get the following result after viewing the source of the resulting page:
<html><body></body></html>
These happen to be the fist 2 and last 2 lines of the file I am trying to read.
Posted: Mon May 02, 2005 3:39 pm
by shiznatix
try it on a local .html file and see the results. im really not sure how any of this functions as i have never done it before but this has been discussed many many times on these forums, use the search feature and im sure you can come up with somthing.
after just trying to view the site it seams that it needs security certificutes to view it? that is probely why u can only get those 4 lines because your severs php dosnt have the permissions to view that website
Posted: Mon May 02, 2005 3:57 pm
by smashy
Everything works on local files or even regular webpages. I am able to use these functions in other projects I am doing no problem. These projects involve flat data file (txt) or simple webpages that can be accessed through http. The system I am testing this code on has the certificate for the site installed (even the passwords are saved, lol).
The root of this thread is how to handle connecting through https, or maybe it the cgi that is confusing the code...
Thanks for all the suggestions so far.
Posted: Mon May 02, 2005 4:14 pm
by shiznatix
the system might have the certificts but your PHP does not. i dont know of any ways to make php able to do that because of obvious security issues
i.e. if you pay for some sort of website you could just make your own website based off the content of the other website becasue you have the cirtificutes. that wouldnt make any sence, so i really do think that its possible just because its a security issue