469,590 Members | 2,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

How to tell if Mime type matches contents

Hi Everyone,

Before I write the script myself, I'm looking for PHP code that checks
that a link's content type matches it's contents. I need this for my
"broken link" checker script, which fails to spot the "broken" links
http://www.awin1.com/show.php?mid=10...6515&aid=49007 and
http://www.awin1.com/awclick.php?mid...36515&id=49007. Any
ideas?

BTW, in case the links get fixed before you read the message, the first
link is a GIF MIME that returns

[document.write('<a
href="http://www.affiliatewindow.com/?id=.&banner=no"
target="_blank"><img
src="http://www.awin1.com/show.php?mid=3&gid=14&aid=477&clickref=nobanner"
border="0"></a>')]

which displays as

[The image
"http://www.awin1.com/show.php?mid=1014&linkid=36515&aid=49007"
cannot be displayed, because it contains errors.] .

The second is a text/html that returns

[<br />
<b>Warning</b>: mysql_result(): Unable to jump to row 0 on MySQL
result index 30 in <b>/home/sites/site3/web/awclick.php</b> on line
<b>51</b><br />
<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid
MySQL result resource in
<b>/home/sites/site3/web/linkdeliveryfunctions.inc.php</b> on line
<b>178</b><br />
<br />

<b>Warning</b>: mysql_result(): supplied argument is not a valid MySQL
result resource in
<b>/home/sites/site3/web/linkdeliveryfunctions.inc.php</b> on line
<b>478</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already
sent by (output started at /home/sites/site3/web/awclick.php:51) in
<b>/home/sites/site3/web/linkdeliveryfunctions.inc.php</b> on line
<b>462</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already
sent by (output started at /home/sites/site3/web/awclick.php:51) in
<b>/home/sites/site3/web/awclick.php</b> on line <b>235</b><br />
]

Thanks,
Ed

Dec 27 '05 #1
1 2397
On 27 Dec 2005 07:27:06 -0800, "ed_spain" <ed********@gmail.com> wrote:
Before I write the script myself, I'm looking for PHP code that checks
that a link's content type matches it's contents. I need this for my
"broken link" checker script, which fails to spot the "broken" links
http://www.awin1.com/show.php?mid=10...6515&aid=49007 and
http://www.awin1.com/awclick.php?mid...36515&id=49007. Any
ideas?

BTW, in case the links get fixed before you read the message, the first
link is a GIF MIME that returns

[document.write('<a
href="http://www.affiliatewindow.com/?id=.&banner=no"
target="_blank"><img
src="http://www.awin1.com/show.php?mid=3&gid=14&aid=477&clickref=nobanner"
border="0"></a>')]

which displays as

[The image
"http://www.awin1.com/show.php?mid=1014&linkid=36515&aid=49007"
cannot be displayed, because it contains errors.] .

The second is a text/html that returns

[<br />
<b>Warning</b>: mysql_result(): Unable to jump to row 0 on MySQL
result index 30 in <b>/home/sites/site3/web/awclick.php</b> on line
<b>51</b><br />
<br />


There's MIME-type detection using "magic numbers" available through:
http://uk2.php.net/mime_content_type

This does a quick check against the first few bytes of the file to see if it
matches up with various file formats.

It won't catch the second one, because that's still a valid HTML page - it may
have PHP errors on it, but they're in HTML.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 30 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by lawrence | last post: by
303 posts views Thread by mike420 | last post: by
1 post views Thread by John B. Kim | last post: by
reply views Thread by clevariant | last post: by
1 post views Thread by Michael Loughry | last post: by
reply views Thread by Ed Eichman | last post: by
reply views Thread by José Joye | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.