php - How to tell if user entered http:// in a form entry -
this question has answer here:
i have form allowing users enter in referral link (url). need sure entered http:// first before url. if entered it's ok, if did not enter need add before placing url in database.
how can check in php before saving form in database?
use substr (and don't forget "https://" , "//") :
<?php $url = 'example.com'; // here url got in input if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') $url = 'http://'.$url; else if (substr($url, 0, 2) == '//') // "//" valid, means browser needs continue using http or https depending on using $url = 'http:'.$url;
Comments
Post a Comment