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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -