Jump to content

[SOLVED] check if http:// was entered


htmlstig

Recommended Posts

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

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;

}

 

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]");
}
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.