0

I'm struggling a bit figuring out the best way accept and store a url from a web page.

Here's my approach:

  1. It should be urlencoded since it's sent over the net to the server.

  2. Specify the page as utf-8 in the header.

  3. Use my_real_escape_string for inserting to the db.

  4. Use strip_slashes on the input.

Does this make sense?

3
  • 3
    Where it should be urlencoded? On the server? After it's already got sent over the net? What's the point in it? why use strip_slashes on the input? what's so particular in storing urls, making it's processing different from whatever other data? Commented Jan 10, 2012 at 2:38
  • Maybe I'm just overthinking it. I saw an example site that strip_slashed everything. I guess it has something to do with escape characters being inserted by the browser. Commented Jan 10, 2012 at 3:05
  • stripslashes is never the correct tool to use. If you are encountering data that has slashes unexpectedly, then chances are that your server has magic_quotes enabled and you should find a competent host ASAP. Commented Jan 10, 2012 at 5:14

2 Answers 2

1

actually, you just need to validate, escape and trim a urls.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you give an example of escaping it?
Depends on what extension you use. It could be mysql_real_escape_string() or prepared statements of PDO...
1

Use PDO for the database. And just trim your url.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.