Log in

View Full Version : PHP: Getching foldername from URL



cancer10
03-16-2008, 03:45 AM
Hi,

I came up with this problem last night.

I have a URL http://www.mysite.com

How do I fetch the folder name that was supplied in the URL.

For example:


http://www.mysite.com/xyz
or
http://mysite.com/myfolder
or
http://www.mysite.com/xxx


Please note that I can either use www or http://www or just http:// in my domain name but I need to fetch the folder name that was supplied in the URL.

PS:

I tried the following code, but it didnt revealed the foldername supplied


<?php
echo $_SERVER['HTTP_HOST'];
?>




Please help.


Thanx

city_coder
03-16-2008, 10:27 AM
You would have to send it through a form and then catch it on the PHP side.

so it would be:



<form action="processor.php" method="get" name="example">
<input type="textbox" name="folder_name">
<input type="submit">


and on the processor part it would be



<?
$folder = $_GET['folder_name'];
//do what ever with the variable $folder

alexjewell
03-16-2008, 12:51 PM
Or you could use explode() (http://www.php.net/manual/en/function.explode.php) to get just that part of the url.