Is it safe to use (strip_tags, stripslashes, trim) to clear variable that holds URLs

964 Views Asked by At

It's quite pleasure to be posting my first question in here :-)

I'm running a URL Shortening / Redirecting service, PHP written. I aim to store and handle valid URLs data as much as possible within my service.

I noticed that sometimes, invalid URL data is being handled over to the database, holding invalid characters (like spaces in the end or beginning of the URL).

I decided to make my URL-Check mechanism trim, stripslashes and strip_tags the values before storing them.

As far as I can think, these functions will not remove valid charterers that any URL may have.

Kindly, just correct me or advise me if I'm going into the wrong direction.

Regards..

1

There are 1 best solutions below

0
On

If you're already trimming the incoming variable, as well as filtering it with the other built in PHP methods, and STILL running into issues, try changing the collation of your table to UTF-8 and see if that helps you get rid of the special characters you mention. (Could you paste a few examples to let us know?)