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 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/ .

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 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.




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 "//"

People are also looking for solutions to the problem: javascript - authenticate via .htaccess on custom login


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.