Jump to content

Simple if(strpos question


djtozz

Recommended Posts

I'm trying to undertsand a simple "strpos" sample, but I'm not able to make this work.

 

<?php

$website = "http://www.zshare.net/download/664558148eb3f5z1/";

if(strpos($website,"Downloading")===true){ //check if page contains the word downloading

echo 'Good link<br >'; 

}

else {

echo 'Expired link<br >'; 

}

?>

 

 

Sample links:

 

Working link: http://www.zshare.net/download/664558148eb3f5d1/

 

Expired link: http://www.zshare.net/download/7759897667114c3e/

 

Am I missing something here, or is there an alternative way to do this?

 

Thank you!

 

 

 

Link to comment
Share on other sites

Thanks for your reaction,

Yes, I just want to see if the html content contains that word, if so then the link is Ok.

In that case, you need to retrieve the content of the page, using either curl, or file_get_contents();

$website = "http://www.zshare.net/download/664558148eb3f5z1/";

$content = file_get_contents($website);

$findme   = "Downloading";
$pos = strpos($content, $findme);


if ($pos === false) {
   echo "Expired link<br >";
} else {
   echo "Good link<br >";
}

Note that you may not have permission to access urls using file_get_contents();

Link to comment
Share on other sites

In that case, you need to retrieve the content of the page, using either curl, or file_get_contents();

 

Thank you Mark, your code is working now for rapidshare, megaupload and probably all others.

 

However Zshare seems to be very tricky:

When clicking a bad link: http://www.zshare.net/download/664558148eb3f5d2/ (you get error 404)

 

But I think they're using some kind of redirect for the 404, because If I check the same url with your code and echo the $content I do see the file info:

http://siana.be/search/cron/test.php  while there is nothing to download.

 

so $findme  = "Downloading"; won't work here

 

I think I need something like following

"If page gets redirected to http://www.zshare.net/file-404.html then print bad link"

 

But I really don't have a clue how to solve this.

Any help should be apriciated!

 

 

 

 

 

 

 

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.