wadie Posted January 27, 2012 Share Posted January 27, 2012 I'm trying to create a function which checks if a url has been posted before,and if it has then an error is given. This is what I have so far in /includes/functions_posting.php function http_file_exists($url) { $f = @fopen($url,"r"); if($f) { fclose($f); return true; } return false; } And this is what I have in posting.php if ($submit || $preview || $refresh) { $post_data['your_url'] = "http://www.google.com"; //remove the equals and url value if using in real post $your_url = $post_data['your_url']; $your_url_exists = (isset($your_url)) ? true : false; $your_url = preg_replace(array('#&\#46;#','#&\#58;#','/\[(.*?)\]/'), array('.',':',''), $your_url); if ($your_url_exists && http_file_exists($your_url) == true) { trigger_error('exists!'); } else if ($your_url_exists && http_file_exists($your_url) == false) { trigger_error('doesnt exist..'); } It works fine,but I still don't know how to do one last thing. if the url doesn't exist,I want it to continue posting. else,trigger the error message that url exists. I think I'm close,but not sure where to go now Quote Link to comment https://forums.phpfreaks.com/topic/255909-last-thing-in-checking-url-function/ Share on other sites More sharing options...
trq Posted January 28, 2012 Share Posted January 28, 2012 It's pretty simple logic: if (http_file_exists($your_url)) { trigger_error('exists!'); } else { // do whatever else you want. } Quote Link to comment https://forums.phpfreaks.com/topic/255909-last-thing-in-checking-url-function/#findComment-1311888 Share on other sites More sharing options...
wadie Posted January 28, 2012 Author Share Posted January 28, 2012 ohh sorry about that,I just copied my previous question. I know how to do that,I just removed the else part and it works. My question is: How do I let it check the whole url and not the domain name only ? for example http://www.google.com/this Quote Link to comment https://forums.phpfreaks.com/topic/255909-last-thing-in-checking-url-function/#findComment-1311922 Share on other sites More sharing options...
trq Posted January 28, 2012 Share Posted January 28, 2012 You don't have to do anything. Just pass it a complete url. Quote Link to comment https://forums.phpfreaks.com/topic/255909-last-thing-in-checking-url-function/#findComment-1311923 Share on other sites More sharing options...
wadie Posted January 28, 2012 Author Share Posted January 28, 2012 It's not working that way. There's even another problem which is it doesn't matter what's the full URL. it's enough to assign http://www. to the variable $post_data['your_url'] and then it will always show that the url exists no matter what's the url I'm trying to post. I'd really appreciate it and even willing to pay if someone can make it fully work cause it's getting on my nerve now Quote Link to comment https://forums.phpfreaks.com/topic/255909-last-thing-in-checking-url-function/#findComment-1311933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.