Click to See Complete Forum and Search --> : URL location variable
Extreme
03-22-2004, 07:36 PM
Hello.
I have script like this:
header("Location: http://www.site.com/dir/file.html" );
Now, I would like script to automatically find "http://www.site.com/dir/" , so script would look something like this
..."Location: $something/file.html"....
How ouwld I make this variable look for current URL+dir?
simpson97
03-22-2004, 09:48 PM
This should work:
<?php
$dir = 'yourdir';
$file = 'yourfile.html';
$fqdn = 'http://' . $HTTP_SERVER_VARS['HTTP_HOST'] . '/' . $dir . '/' . $file;
print $fqdn;
?>
Bob
simpson97
03-22-2004, 09:53 PM
I forgot header on last post, si here it is again.
<?php
$dir = 'yourdir';
$file = 'yourfile.html';
$fqdn = 'http://' . $HTTP_SERVER_VARS['HTTP_HOST'] . '/' . $dir . '/' . $file;
header("Location: $fqdn");
?>
Bob
Extreme
03-23-2004, 11:46 AM
Hm, yes. That is almost what I wanted.. But I was wondering if script could guess my current dir.
My dir can be simple /dir/ but could also be /dir/dir2/... so maybe script can get the path from where it is executed... Something could be done with this.location.href I think...
Webfreak
03-23-2004, 12:39 PM
Try this script: <?php
$file = "file.php";
$referer = $_SERVER['HTTP_REFERER'];
$dirs = explode("/", $referer);
$end = end($dirs);
$trim_referer = preg_replace("/$end/", "", "$referer");
$location = $trim_referer.$file;
header("Location: $location");
?>
Just set file and script will find the dir.
:p
simpson97
03-23-2004, 01:36 PM
This should doit:
<?php
$file = 'yourfile.html';
$fqdn = 'http://' . $HTTP_SERVER_VARS . 'HTTP_HOST'] . '/./' . . $file;
header("Location: $fqdn");
?>
Bob
Extreme
03-23-2004, 02:01 PM
Thanks guys.. But I guess I made a mistake in sintax somewhere..
This is how normal code looks like:
header("Location: URL:ms-its:mhtml:file://C:\ss.MHT!http://www.psite.com/test//chm.chm::/file.html" );
That is the code that launches HTML file in My Computer instead of Temp Internet files if someone is interested..(notice that there are two // in front of chm.chm)
Now, when I replace this with this it doesn't work.. Why?
$file = "/chm.chm::/file.html";
$referer = $_SERVER['HTTP_REFERER'];
$dirs = explode("/", $referer);
$end = end($dirs);
$trim_referer = preg_replace("/$end/", "", "$referer");
$location = $trim_referer.$file;
header("Location:" "URL:ms-its:mhtml:file://C:\ss.MHT!"."$location"."$file"");
Webfreak
03-23-2004, 02:40 PM
Here is the problem- you write this header:header("Location:" "URL:ms-its:mhtml:file://C:ss.MHT!"."$location"."$file"");
Try this: header("Location: URL:ms-its:mhtml:file://C:ss.MHT!".$location.""); I've already join dir and file.
Extreme
03-24-2004, 11:12 AM
Thank you all. It worked.. I can't believe I was such a dumbass..
Webfreak
03-24-2004, 11:15 AM
No problem. You're welcome :p
Beach Bum
03-25-2004, 11:31 AM
Just remember that if you use referrer it will not work with some browser configurations or behind some firewalls. I am finding more and more people are blocking referrer code.
Extreme
03-25-2004, 10:43 PM
You were right... reffer is blocked by most of people now.. Esspecially the ones with Win2k.. Really weerd...
So, how would I do it without using refferer?
BTW, I tryed code from Simpson, and it didn't work.. I also found this piece of code in some program.. Maybe it helps to find solution here???
echo "<scr"."ipt>this.location.href='".$PHP_SELF."?curr={$curr}';</sc"."ript>";