Jump to content

How to read the headers coming from the server in php?


tommytx

Recommended Posts

There is a lot of sites offering a free header check where you can enter any url even with an html page and it will tell you all the headers. Especially useful when you are wondering if your site is throwing out a 404 when you have a page missing. Lots of sites throw out a 500 which is not good.

The code to read headers should be a short little program in php.
Can anyone steer me to where I might find this source code or maybe even dump it on me here, I would be forever grateful.

I have seen a lot of how to send headers using php but what I need is how to read the headers when you visit a site.....

Thanks
Tom
Link to comment
Share on other sites

So you want to see header information when someone visits your site??? Or do you want to show the header information between visitors to your site and your server?? Or do you want to create something that makes a request to a provided URL and see the headers? Your post was a bit confusing. Maybe list the URL that you are speaking of where this functionality already exists.
Link to comment
Share on other sites

[quoute]
There is a lot of sites offering a free header check where you can enter any url even with an html page and it will tell you all the headers.
[/quote] from above...

LD,
I explained above, that I want to have a php form on my site so that somene can visit and enter a url to one of their sites and it will load thier page and feed them back the results like a 200 if ok or a 404 for page not found... This is a popular script and you see it on tons of sites.

Jr,
I have studied that script before, and could not figure out how to do it, but I will re-visit it again and see if I can make heads or tails of it.

Thanks to both of you for your reponses...  hopefully I have clarified it more.

Link to comment
Share on other sites

Thanks for your input Guru, but it appears that I am not making myself clear.
If I undestand your code correctly, if I place it in a php file on my server and visit that page it will give me the headers for my own server.  I want to see the headers sent from the remote server when I query them for a page.

I will try to explain in other words what I am trying to do.

I want to have a form on my site the will allow someone (a visitor) to fill in their url and when submitted, the php code in this form/php file will visit the page they have entered and tell them the headers of the remote site they have enterer.
Like 404 for can't find and 200 for ok and etc.... since this seems to not be clear  I have included an exact example of what I am trying to do with a sample at

http://www.webmaster-toolkit.com/http-header-viewer.shtml


Link to comment
Share on other sites

You probably want to look into CURL. I have written a CURL class that makes page retrieval easy. There is also an option to show the headers.

[code]
<?php
require_once('ripcurl.class.php');
$rip = new ripcurl();

$url = "http://someurl.com";
$rip->showHeader();
$rip->ripRun($url, 1);
echo $rip->getRawHtml();
?>
[/code]

The output of the above would be the header information followed by the actual page. You could preg out any information you needed. The class is located at http://ripcurl.sdsustudent.com or http://sourceforge.net/projects/ripcurl/
Link to comment
Share on other sites

Thanks Linux,
The class looks like a real cool tool and I think will do exactly what I need.
However I am having a problem getting it to load into my DzSoft PhP Editor. Is it protected so I can't view the code in the class using the Editor... I can load the class into a text editor, but all scrambled so hard to read. The php editor will straighten it up.  I did try to upload in both text and binary for the class but no joy either way.

Normally I can see code in the class in the DzSoft Php editor.

I copied the code you wrote above and renamed the class as you have it but I got this error...

Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/adsentry/public_html/ripcurl.class.php on line 12

any ideas come to mind..... its on http://www.adsentry.net/header_ripcurl.php
with the class named  ripcurl.class.php
When the url above is activate the error is as shown... I will include my actual code used to load the class below:
<?php
require_once('ripcurl.class.php');
$rip = new ripcurl();

$url = "http://vahud.com";
$rip->showHeader();
$rip->ripRun($url, 1);
echo $rip->getRawHtml();
?>

Oh by the way I did download from both of the sites you gave with the same results from both sites.

I really would like to get the class going as there is a lot of features that I would like to experiment with....

Thanks again.

Link to comment
Share on other sites

That's funny... I don't know why the class would come across all messed up. I've edited it in vi and Zend and it looks fine. Try this link to the file in txt format: http://ripcurl.sdsustudent.com/releases/ripcurl.class.txt
Copy and paste or change the extension to .php and all should be well. I better check my tar files to be sure there's nothing wrong with them.

Otherwise, what you have should be working. Let me know if the txt file didn't work.
Link to comment
Share on other sites

Thanks that was perfect only 30 k and looks great... below is the first few lines of the code in the gz that I downloaded.... and it is 160k if you can believe that....

ripcurl.class.php                                                                                  0000644 0001750 0001750 00000067564 10554246761 013351  0                                                                                                    ustar  ching                          ching                                                                                                                                                                                                                  <?php
//RipCURL class 0.4 - SD Linux Services
//This class was written by Brandon Ching of SD Linux Services
//It is licensed under the GPL


class ripCurl{
//Class definitions
//Define the default directory for ripWrite. Must include


I will try the new pgm now and let you know....
But this looks great... thanks again...

By the way below is what the 30k file looks like and it looks sweet..
I will try my unzipper again tomorrow to see if there is something wrong with my unzip... it has been working fine for years.....

<?php
//RipCURL class 0.5.2 - SD Linux Services
//This class was written by Brandon Ching of SD Linux Services
//It is licensed under the GPL


class ripCurl{
//Class definitions
//Define the default directory for ripWrite. Must include trailing "/".
Link to comment
Share on other sites

linuxdream
********
It is giving the very same error on 3 servers as shown below. Is there a simple "hello world" script I can use to get down to real basics to see if my setup will work at all. Also is there a forum anywhere that discusses this class so I don't keep wasting your time.

Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/ownahome/public_html/ripcurl.class.php on line 15

http://www.adsentry.net/header_ripcurl.php
http://www.vahud.com/header_ripcurl.php
http://www.2ownahome.com/header_ripcurl.php

All 3 sites are still in place in case you want to visit them to see the error.

this looks like a great class, I hope I can get it working.. thanks again.
Link to comment
Share on other sites

tommytx,
That's really strange, line 15 of the ripcurl class is actually a comment..

12. const WRITEDIRECTORY = "/tmp/";
13.
14.  //Set class variables
15.  //curl handler
16. private $ch;

Sorry this is becomming such a pain. I haven't had these problems on the various servers I run with this class. All my servers are Ubuntu/PHP5/Mysql5 boxes.
What is line 15 on your version of the class? I can only assume that it's because of the WRITEDIRECTORY constant on line 12 of the class. Though I don't know why it would choke there (old PHP version maybe... I really don't know)???
Unfortuantely there are no forums...just me. I don't mind any questions so feel free to ask. Check my profile for my email, I think it's there. I have some basic documentation with samples of some of the methods here: http://ripcurl.sdsustudent.com/documentation/ripcurl_documentation.pdf
That should be enough to get you started...but about the error, I can't reproduce it so I don't know. Maybe change the name of the class you have to end in .txt and post (or email me) the link. That way I can see exactly the content of the class and look for errors. That's really strange, I've been packing and unpacking the tar file many times on different machines and have yet to have any problems.

Thanks,

Link to comment
Share on other sites

Formal Thanks to linuxdream..
He actually set me up on his own server to tackle my problem... now that is what I call helping out.....
Actually I am a little embarrased as there was nothing wrong with his class.... speaking of that it is a reall class program... I am sure a lot of work went into it..  Anyway so linux doesn't have to embarrass me which I am sure he wouldn't anyway for anyone who is following this thread the only problem was the fact that all of my VPS one on slhost and one on hostgator were still running the old 4.4.4 version of PHP and of cours linus state of the art class doesn't go for that old stuff... so I am in the process of beating up the hosts to get then to update the php.

Thanks again linux you are the best.
For anyone following this thread, it pops out a great header just like the doctor ordered and not my local header, its the header of the site that the url is used on...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.