trailing slashes in url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
afs
Forum Newbie
Posts: 5
Joined: Tue Nov 07, 2006 7:21 pm

trailing slashes in url

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It generally shouldn't make a difference to PHP.

Can you post your code?
afs
Forum Newbie
Posts: 5
Joined: Tue Nov 07, 2006 7:21 pm

Post by afs »

feyd | Please use

Code: Select all

,

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

,

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]
afs
Forum Newbie
Posts: 5
Joined: Tue Nov 07, 2006 7:21 pm

Post 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??
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
afs
Forum Newbie
Posts: 5
Joined: Tue Nov 07, 2006 7:21 pm

Post by afs »

excellent. Now, how do i stop it?? What is the workaround or methods to avoid it?

Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Code: Select all

rtrim($string, '/');
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Why no absolute path?

Code: Select all

<img src="/graph.png">
Post Reply