php - Link does not work without http:// protocols
I use php and I have an input that the user types in a link to his website. The link should appear for others to view it or open it. I'm testing the input and the problem is the link does not work unless I types either http:// or https:// before the mentioned URL and I think some one might just write www.foo.com without writing the hhtp:// . The link automatically substitutes the http:// or https://with the root of my website ( or at least that's what I guess ), because I'm working with XAMP and the URL appears as localhost/MyFooProjectFile/www.foo.com .
How to make link work without the protocols or substitute the none mentioned protocol with the right one before my user's link ?
Note : I know the question might seem stupid (cause who is the idiot who thinks a link could work without protocol), but what makes me wonder is I write in the address bar of my browser www.foo.co and it would take me there, without me menthionioning the protocols.
PLease note that I do not have the code in the time of writing the question.
Answer
Solution:
Duplicated With HTML5 url input validation assume url starts with http://
Trust in the urls user inputed is in danger. You have to filter the urls, parse them, construct them, test them, then embed them in your page.
Not all the URL must have "//"