Solved

proper way to strip backslashes from url

Posted on 2009-07-01
3
308 Views
Last Modified: 2012-05-07
I need to know a proper, secure, and proficient way to strip not only front slashes but backslashes as well from a url.

the current code im working with is

define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/') . dirname($_SERVER['PHP_SELF']), '/'));

but it does not strip backslashes which might appear on wamp setups (windows systems)
0
Comment
Question by:redcable
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
kevin_u earned 500 total points
ID: 24758998
define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/\\') . dirname($_SERVER['PHP_SELF']), '/\\'));


That will strip trailing / or \... but I'm not sure if thats what you wanted.
0
 

Author Comment

by:redcable
ID: 24759161
define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/\\') . dirname($_SERVER['PHP_SELF']), '/\\'));

ahh ok i was close. thanks any downside to doing it this way?
0
 
LVL 12

Expert Comment

by:kevin_u
ID: 24759690
I can't say there's a downside, unless I know what you are trying to accomplish.

What is DOMAIN used for in the rest of the script?

What if the PHP_SELF has back slashses embedded in it instead of just at the end?

A few examples would help me understand the question.

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question