Soy un corredor
-
Posts
5 -
Joined
-
Last visited
Never
Posts posted by Soy un corredor
-
-
[code]$fname = $_SERVER['SCRIPT_FILENAME'];[/code]
This includes the file name AND the directory where it's located. Perhaps it'll be best if I explain my overall goal here...
My web host allows subdomains, but there are only "aliases" of directories. Meaning, [i]subdomain.site.com = site.com/subdomain[/i]. If a user goes to the address [i]site.com/subdomain/file.php[/i] I want them to be redirected to [i]subdomain.site.com/file.php[/i]. I hope that clears things up. Here is the code that I've been working with:
[code]<?php
$domain = 'site.com';
$wwwdomain = 'www.site.com';
$url = ''.$_SERVER['HTTP_HOST'];
$root = ''.$_SERVER['PHP_SELF'];
$file = basename($root);
if ( $domain == $url ) {
header("Location: http://subdomain.site.com/$file");
exit;
} elseif ( $wwwdomain == $url )
{
header("Location: http://subdomain.site.com/$file");
exit;
}
?>[/code]
THIS CODE WORKS GREAT BUT not when the address is [i]site.com/subdomain/file.php?[b]id=5[/b][/i] (for example). They will just be redirected to [i]site.com/subdomain/file.php[/i]. Any ideas?
Thanks! -
Sorry to post back so soon, but I have a follow-up question regarding my script [above]. Let's say, for example, that the file was [i]view.php?id=3[/i]
The above code will only display [i]view.php[/i] . How do I resolve this? -
I added the basename() function to my current code and came up with this:
[i]$php_self = ''.$_SERVER['PHP_SELF'];
$file = basename($php_self);[/i]
Works now ;)
[b]¡Gracias a todos![/b] -
Hello.
I'm having a little trouble here. For the sake of simplicity, I'll give an example. Say I have a php file and the location of the file is:
[i]http://www.site.com/foldera/folderb/file.php[/i]
Each time I try to display [b]just[/b] the file name, I get this: [i]/foldera/folderb/file.php[/i]
How can I get just: [i]/file.php[/i]
Thanks!
Display ONLY file name
in PHP Coding Help
Posted