How can I get just the filename of the originating document?

How can I get just the filename of the originating document?
$ref=@$_SERVER[HTTP_REFERER]; gives me the full http path
$ref=@$_SERVER[REQUEST_URI]; gives me the /directoryname/filename
I only want the filename. Nothing else.
Can you help?
Thanks
Sas
LVL 1
sasnaktivAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
On many servers, 'SCRIPT_NAME' gives you just the filename.  However, this is not guaranteed.  Each server and admin may provide a different set of values because they all come from the server.

http://php.net/manual/en/reserved.variables.server.php

I use this program to see what my servers provide.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>PHP Server Variables</title>
</head>
<body>
<h1>PHP Server Variables</h1>
<?php

//reset($_SERVER);
foreach($_SERVER as $key => $value) {
    echo "<b>$key :</b> $value<br />\n";
}
?>
</body>
</html>

Open in new window

0
sasnaktivAuthor Commented:
Thanks for your quick response Dave,
Your list gives me a lot of information that I'm not looking for.
And it doesn't give me the simple, isolated filename that I am looking for.
I just want the 'filename' not its directory, not its path.
Can you isolate the 'filename'?
Sas
0
Dave BaldwinFixer of ProblemsCommented:
Apparently not.
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

sasnaktivAuthor Commented:
So much for PHP.
Do you know how I can delete everything before the 'filename'?
That might be a solution.
Thanks for the help, Dave
0
Dave BaldwinFixer of ProblemsCommented:
No need to do that.  This should work.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Get Filename</title>
</head>
<body>
<?php 
$fn = $_SERVER['SCRIPT_NAME'];
$fn2 = explode('/',$fn);
foreach($fn2 as $value) {
	$fn3 = $value;
	}
echo $fn3;
 ?>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sasnaktivAuthor Commented:
That's nice Dave, except for one thing.
It shouldn't be $fn = $_SERVER['SCRIPT_NAME'];

Instead it should be: $fn = $_SERVER['HTTP_REFERER'];

Because $fn = $_SERVER['SCRIPT_NAME']; returns the filename of the current document.
Whereas $fn = $_SERVER['HTTP_REFERER']; returns the filename of the referring document. And it's the referring document that I've been looking to capture.

Thanks for your patience and knowledge.
Sas
0
sasnaktivAuthor Commented:
Much appreciated, Dave.
Sas
1
Dave BaldwinFixer of ProblemsCommented:
You're welcome.  You said 'originating document' and I thought you meant the name of the page.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.