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

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -