|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 2,325 Joined: 8-March 05 From: Mawson, Antarctica Member No.: 4,254 |
Post
#1
Apr 8 2005, 03:29 AM
Hey I want to know how to get the filename of the referring URL. Look at the following example: Page A which has a URL of http://blah.trap17.com/blah/blah1.php redirects the user to Page B which has a URL of http://blah.trap17.com/blah/blah2.php. Is there a PHP code that I can put on blah2.php that will output blah1.php? I tried _SERVER["HTTP_REFERRER"]; (please note the code may not exactly be correct as I do not remember the code Thanks in advance! |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 463 Joined: 8-November 04 Member No.: 2,186 |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 113 Joined: 14-January 05 From: Philippines Member No.: 3,271 |
Post
#3
Apr 8 2005, 04:08 AM
just manipuate the url. [CODE]$filename strrpos($_SERVER['HTTP_REFERER'], strrpos($_SERVER['HTTP_REFERER'], '/') + 1); |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 873 Joined: 30-July 04 Member No.: 246 |
Post
#4
Apr 8 2005, 08:21 AM
mobious, try closing the CODE tag, buddy. I would use something along the lines of: CODE $url = $_SERVER['HTTP_REFERER'];
if( $url ) { $url = strrev($url); $last_slash = strlen($url) - strpos($url,'/') - 1; $url = strrev($url); if( $last_slash ) { $file_name = substr($url,$last_slash); } } |
![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 113 Joined: 14-January 05 From: Philippines Member No.: 3,271 |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 773 Joined: 4-November 04 Member No.: 2,118 |
Post
#6
Apr 8 2005, 12:55 PM
$path = explode('/', $_SERVER['HTTP_REFERER']); all you need is the above code. It is pretty simple. It will break down your URL into pieces using the "/" (Slash) as the divider. using your url as an example http://blah.trap17.com/blah/blah1.php You will get an array with elements [0] => http: [1] => blah.trap17.com [2] => blah [3] => blah1.php Using this method, you will realize that your filename will be the last element in the array no matter what your URL looks like. Note: unless you are using query strings. since the filename will always reside in the last element in the array, the filename is always under: $path[count($path)-1] using count($path)-1 ensures that even if your referring URL is under any number of directories, you will be able to identify the filename. I am not sure if you are familiar with arrays. If not, then just ignore the explanation and put the following code in your script CODE $path = explode('/', $_SERVER['HTTP_REFERER']); $filename=$path[count($path)-1]; $filename will hold the filename you are looking for. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 873 Joined: 30-July 04 Member No.: 246 |
Post
#7
Apr 8 2005, 01:01 PM
You could use the parse_url() function first, which will return just the path as part of the array (index 'path'). Alternatively, you could try checking the string for '?' (question mark), and trimming it from there. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 2,325 Joined: 8-March 05 From: Mawson, Antarctica Member No.: 4,254 |
Post
#8
Apr 8 2005, 03:10 PM
I tried no9t9's code because his post flowed so well, and it worked! And I also love arrays Spectre, the question mark suggestion would be great except my referring URL does not have a question mark. That's it, question answered. Thanks again guys! |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Post
#9
Nov 11 2008, 05:31 AM
$_SERVER[\\ Get Filename Of Referring Url I have a link which is on a remote place. When the link is clicked it will call my script at my server As my server is in https, the link contains it. Now I don't know where the link is placed and I want to know the referer. I have used $_SERVER['REMOTE_ADDR'] to get the referer IP and it works. But in the case of referer page $_SERVER['HTTP_REFERER'] does not work. What will I do now??? I mean how can I make it working? -question by Himel |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
Post
#10
Apr 4 2009, 03:39 PM
this code will not work in the example below If the url to be parsed is, for eaxample: http://www.Foo.Com/bar/ The code: $path = explode('/', $_SERVER['HTTP_REFERER']); will return bar/ as the filename, when in fact its a folder. Just thought add meantion it
Keywords: php get requested file name from url |
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
1 | guangdian | 2,478 | 7th February 2005 - 02:29 PM Last post by: OpaQue |
|||
![]() |
9 | ARNEL | 2,743 | 21st May 2005 - 11:04 PM Last post by: badinfluence |
|||
![]() |
14 | irmlm | 1,290 | 10th October 2006 - 08:37 PM Last post by: heavensounds |
|||
|
Open Discussion | Time is now: 6th November 2009 - 07:40 PM |
Web Hosting Powered by ComputingHost.com.