NeTech-UK Posted November 6, 2008 Share Posted November 6, 2008 alas another problem I am creating a shorturl redirect script for a client which can be seen here; http://portfolio.netech-uk.com/shorturl/ A specific request was that the link entered is validated on the fly, either with or without the "http://" and the "www." the problem i am having is that it will verify any of the following URL's. http://www.ziddu.com http://ziddu.com www.ziddu.com ziddu.com http://www.ziddu www.ziddu obviously i dont want it to validate the last two url's in that list code is as follows... <?php include 'config.php'; //=========================================== // CHECK TO SEE IF THE LINK SUPPLIED IS VALID //=========================================== $testurl = htmlspecialchars($_POST['url']); if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i",$testurl)) { if (!preg_match("/^([\w\-]+\.[\w\-]+)/i",$testurl)) { $linkvalid = 0; $error = "Link Is Invalid"; } else { $linkvalid = 1; $error = "None"; } } else { $linkvalid = 1; $error = "None"; } //============================================== // CHECK TO SEE IF THE CHOSEN TAG ALREADY EXISTS //============================================== $getdata = mysql_query("SELECT * FROM shorturl_redirects WHERE tag = '$tag'"); while ($data = mysql_fetch_array($getdata)) { $linkvalidated = 0; $tagexists = 1; $error = "Tag Already Exists!"; } //======================================= // CHECK TO SEE IF THE CHOSEN URL EXISTS //======================================= $getdata = mysql_query("SELECT * FROM shorturl_redirects WHERE url LIKE '%$url%'"); while ($data = mysql_fetch_array($getdata)) { $linkvalidated = 0; $linkexists = 1; $error = "URL Already Exists!"; } //================================ // IF NO ERRORS GIVE THE ALL CLEAR //================================ if (($linkexists != 1) && ($tagexists != 1) && ($linkvalid == 1)) { $linkvalidated = 1; $error = "None"; } Any Help Would Be Appreciated Link to comment https://forums.phpfreaks.com/topic/131703-solved-url-verification-issues/ Share on other sites More sharing options...
NeTech-UK Posted November 7, 2008 Author Share Posted November 7, 2008 Thanks to several jars of coffee and a severe lack of sleep I have found the problem with this script. For those of you that are interested the new code is as follows... <?php include 'config.php'; //=========================================== // CHECK TO SEE IF THE LINK SUPPLIED IS VALID //=========================================== $testurl = htmlspecialchars($_POST['url']); if (!preg_match("/^(www\.)+([\w\-]+\.[\w\-]+)/i",$testurl)) { if (!preg_match("/^([\w\-]+\.[\w\-]+)/i",$testurl)) { $linkvalid = 0; $error = "The Link You Have Supplied Is Invalid"; } else if (preg_match("/^(www\.)+([\w\-]+)/i",$testurl)) { $linkvalid = 0; $error = "The Link You Have Supplied Is Invalid"; } else { $linkvalid = 1; $error = "None"; } } else { $linkvalid = 1; $error = "None"; } //============================================== // CHECK TO SEE IF THE CHOSEN TAG ALREADY EXISTS //============================================== $getdata = mysql_query("SELECT * FROM shorturl_redirects WHERE tag = '$tag'"); while ($data = mysql_fetch_array($getdata)) { $linkvalidated = 0; $tagexists = 1; $error = "This Tag Already Exists In The Database!"; } //======================================= // CHECK TO SEE IF THE CHOSEN URL EXISTS //======================================= $getdata = mysql_query("SELECT * FROM shorturl_redirects WHERE url LIKE '%$url%'"); while ($data = mysql_fetch_array($getdata)) { $linkvalidated = 0; $linkexists = 1; $error = "This URL Already Exists In The Database!"; } //================================ // IF NO ERRORS GIVE THE ALL CLEAR //================================ if (($linkexists != 1) && ($tagexists != 1) && ($linkvalid == 1)) { $linkvalidated = 1; $error = "None"; } Link to comment https://forums.phpfreaks.com/topic/131703-solved-url-verification-issues/#findComment-684439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.