htmlstig Posted January 1, 2009 Share Posted January 1, 2009 hi i have worte a simple script that has a form and uploads the data from the from to a mysql database upon submit. one of my fields is a url field, how would i check to see if the user has entered http:// before the address and if its not there add it to the address before sending it to mysql? Cheers Carl Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/ Share on other sites More sharing options...
corbin Posted January 1, 2009 Share Posted January 1, 2009 if(stripos($url, 'http://') === 0) { //starts with http:// } You could also use regular expressions, but there isn't a very good advantage to that. If you wanted to check for https:// you could just use an ||. Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/#findComment-727553 Share on other sites More sharing options...
htmlstig Posted January 1, 2009 Author Share Posted January 1, 2009 sorry if this sounds daft ... does that add the http:// to the address aswel or does it just check to see if its there? Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/#findComment-727594 Share on other sites More sharing options...
opalelement Posted January 1, 2009 Share Posted January 1, 2009 sorry if this sounds daft ... does that add the http:// to the address aswel or does it just check to see if its there? if(stripos($url, 'http://') == 0) { //starts with http:// } else { $url = "http://".$url; } or to just append it: if(stripos($url, 'http://') != 0) { $url = "http://".$url; } Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/#findComment-727642 Share on other sites More sharing options...
htmlstig Posted January 1, 2009 Author Share Posted January 1, 2009 for some reason i couldnt get those to work this is my code <? if (isset($_POST['submit'])){ $name=$_POST['name']; $email=$_POST['email']; $website=$_POST['website']; $comment=$_POST['comment']; } if(stripos($website, 'http://') == 0) { } else { $website = "http://".$website; } mysql_connect($server, $username, $password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); mysql_query("INSERT INTO `guestbook` VALUES ( '', NOW(), NOW(), '$name', '$email', '$website', '$comment')"); header("location: $_SERVER[php_SELF]"); } ?> Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/#findComment-727664 Share on other sites More sharing options...
opalelement Posted January 1, 2009 Share Posted January 1, 2009 Any errors? Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/#findComment-727666 Share on other sites More sharing options...
Mark Baker Posted January 1, 2009 Share Posted January 1, 2009 Watch the number of = characters if(stripos($website, 'http://') === 0) { } else { $website = "http://".$website; } Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/#findComment-727668 Share on other sites More sharing options...
htmlstig Posted January 1, 2009 Author Share Posted January 1, 2009 thank you that sorted it i didnt notice the difference between the 2 posts Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/#findComment-727686 Share on other sites More sharing options...
opalelement Posted January 2, 2009 Share Posted January 2, 2009 My bad, forgot that last = Link to comment https://forums.phpfreaks.com/topic/139108-solved-check-if-http-was-entered/#findComment-727784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.