Jump to content

Handling user submitted urls


Braxton

Recommended Posts

I am currently writing a simple blog script for my website and I have reached the point where I am writing in the commenting feature. I want to allow the author of a comment to also provide their url much like how wordpress comments work. The thing that I'm unsure about is the url. Some users like to simply type domain.com and other http://domain.com. My question is, is there a function or method of which would be good to use here to make sure that when a user submits the info, the url won't break or anything like that. I hope this makes sense.

Link to comment
Share on other sites

You got the "localhost/" on it because without the leading slash (on "domain.com") the browser thinks it is a relative path, and automatically applies the path of the current page. At the very least, you need a slash at the beginning: /domain.com.

 

However, I would instruct the user to include the protocol ("http:") and reject the submission if it is not present. It is possible that the user's protocol is https:, so you really want to have them enter it, rather than guess.

 

I would resist storing or showing it without the protocol, because if you show it through some other protocol (i.e. rss or some future protocol), you don't really know what that (future) reader will do to unqualified addresses.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.