You don't have to test it on Windows. You just have to do str_replace($url, '\\', '//') at every location in your code which deals with URLs. Backslashes, even encoded ones, are not part of normal common URLs, so this code may even help prevent possible bugs. If you have special needs that require an encoded backslash to be preserved, you can tweak this function. It's that simple.
Furthermore, you really shouldn't be hosting a server on Windows. It's a terrible awful very bad idea. You never know when MS is going to push the next update that's going to crash your server or make the CIA's backdoors to your PC vulnerable or worse. Linux and BSD are where it's at, and any self-respecting dev uses a *nix server.
Agreed. My rule of thumb now that I've discovered this constant is to use it just for file directory access. The problems illustrated seem to only occur when dealing with URLs. For me it's an anal stylistic choice. Thank you for the warning though, Mr Author
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You are not supposed to use DIRECTORY_SEPARATOR on URLs. You should use it only for working with directories and files.
linux user won't notice if their program will return
\
on windows. so they don't recognize if a relative path will be exposed to an url somewhere.You don't have to test it on Windows. You just have to do
str_replace($url, '\\', '//')
at every location in your code which deals with URLs. Backslashes, even encoded ones, are not part of normal common URLs, so this code may even help prevent possible bugs. If you have special needs that require an encoded backslash to be preserved, you can tweak this function. It's that simple.Furthermore, you really shouldn't be hosting a server on Windows. It's a terrible awful very bad idea. You never know when MS is going to push the next update that's going to crash your server or make the CIA's backdoors to your PC vulnerable or worse. Linux and BSD are where it's at, and any self-respecting dev uses a *nix server.
Agreed. My rule of thumb now that I've discovered this constant is to use it just for file directory access. The problems illustrated seem to only occur when dealing with URLs. For me it's an anal stylistic choice. Thank you for the warning though, Mr Author