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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -