Page 1 of 1
trailing slashes in url
Posted: Tue Jan 02, 2007 10:57 pm
by afs
I wondering how to detect trailing slashes in the url.
ie.
localhost/index.php <-- this is good, php finds the includes etc, and images are displayed
localhost/index.php/ <-- this is bad, php find the includes etc, BUT images do not load etc since the base for the html is thrown out.
This issues affects may php sites (not phpBB).
What do I do?
Ps. Did search this site but didn't find anything.
Posted: Tue Jan 02, 2007 11:09 pm
by feyd
It generally shouldn't make a difference to PHP.
Can you post your code?
Posted: Tue Jan 02, 2007 11:27 pm
by afs
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, ok
He is some code, very simple.
Code: Select all
<?
echo "hello";
echo "<img src=\"graph.png\">";
?>
<br>
<img src="graph.png">
Access this code, say "index.php" and the graph image will be displayed twice.
Access this code as index.php/ and then the images will not be displayed, nor will css etc.
I tried this on phpMyAdmin and it just hung.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Jan 04, 2007 6:19 pm
by afs
thanks for the formatting tip, still trying to figure out why the above happens when the extra slash is insert tho.
Has anyone run across this before??
Posted: Thu Jan 04, 2007 7:47 pm
by volka
Your src attributes contain relative urls, i.e. the browser appends the new path to the current path.
http://localhost/index.php <- index.php is the file part of the url, src="graph.png" ->
http://localhost/graph.png
http://localhost/index.php/ <- empty file part, src="graph.png" ->
http://localhost/index.php/graph.png
Posted: Thu Jan 04, 2007 9:33 pm
by afs
excellent. Now, how do i stop it?? What is the workaround or methods to avoid it?
Thanks
Posted: Thu Jan 04, 2007 9:45 pm
by volka
Why would anybody call index.php/?
Take a look at
Code: Select all
echo 'REQUEST_URI: ', $_SERVER['REQUEST_URI'], " <br />\n";
echo 'PATH_INFO: ', $_SERVER['PATH_INFO'], " <br />\n";
Posted: Thu Jan 04, 2007 11:31 pm
by aaronhall
Posted: Fri Jan 05, 2007 12:49 am
by matthijs