Closed Thread Icon

Topic awaiting preservation: Current URL (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12481" title="Pages that link to Topic awaiting preservation: Current URL (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Current URL <span class="small">(Page 1 of 1)</span>\

 
DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 10-20-2002 00:10

Not sure where to go here...no luck figuring out what I need from the manual.

I have a header file, with simple text link navigation, which is inlcuded by all of my content pages.

I want to determine which file is calling the inlcude (what the current page is) and adjust how the navigation is output accordingly.

How do I determine which file is currently being viewed?


Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 10-20-2002 00:55

Well, you didn't say which language, so I'm going to assume PHP. In PHP, you could check what $PHP_SELF is. That should be the document calling the URLs if you're using a page that calls various files. If you have something more complex like pages that call pages that call other pages, I'm not sure.

But $PHP_SELF should be the document in the URI

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 10-20-2002 01:12

heh. Yes, PHP...always forget to specify that here.

I had actually searched the function lisst for 'php_self' as I seemed to remember seeing that...but hadn't thought to expand the search beyond the functions.

Thanks Pugzly =)

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 10-20-2002 03:49

Well, in case it's helpful to anyone else, or in case anyone can see that i'm doing something either stupid or inefficient, here's what I did all in all -


code:
<?php

$links = array
(
'/index.php' => ("Home"),
'/sketches.php' => ("Sketches"),
'/links.php' => ("Links")
);

$cur_page = $PHP_SELF;
$num_links = sizeof($links);
$sep = "&nbsp;&nbsp;-&nbsp;&nbsp;";

foreach ($links as $path => $text)
{

if ($cur_page != $path)
{
$a_open = "<a href=\"$path\">";
$a_close = "</a>";
}

else
{
$a_open = "<span class=\"on\">";
$a_close = "</span>";
}

echo "$a_open$text$a_close$sep";
}

?>



Still being new to all this, it took a bit of thinking on my part to get this done. =)
It's rather simple, of course, but seems easy to expand upon for more complex structures.

Thanks again.

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-21-2002 01:38

If you're on IIS, you won't have the luxury of $PHP_SELF. I wrote a workaround for this; anyone who needs it, give me an email.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 10-21-2002 09:18
quote:
If you're on IIS, you won't have the luxury of $PHP_SELF. I wrote a workaround for this; anyone who needs it, give me an email.



Why is that? I locally run IIS and use $PHP_SELF



Elias,

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-22-2002 00:47

Funny... not only have I run into a lack of $PHP_SELF in IIS, but I've seen numerous write-ups on the topic. Let me rephrase -- if you use IIS, you might not have $PHP_SELF.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 10-22-2002 04:31

hey DL 2 quick tips.

First you don't really need to set $PHP_SELF to $curr_path just use $PHP_SELF on it's own or if you use something like

$curr_path = basename($PHP_SELF);

you'll get just "index.php" etc without the slashes and just the file name if you are not in your home directory.
ie basename("/path/to/whatever.html")

returns just "whatever.html"

Which means you can get rid of some slashes which brings me to my second point. Your array is kinda backwards, it's not really a big issue as long as it works but genrally the way you want hashes (you're making a hash here) like so

$hash['key'] = "VALUE where this is all your wierd data";

you have it like :

$hash['VALUE where this is all your wierd data'] = 'key'

just a little backwards.



.:[ Never resist a perfect moment ]:.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 10-22-2002 14:20

Bit - the $cur_page I had initially imagined broader plans for, and had thought I would have to alter the info from the $PHP_SELF before using it...never went back to remove it.

The array itself had also started out larger and more complex, so it didn't seem so strange then. It looks kinda funny now though

Thanks for the tips - I'll switch those around.



Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 10-27-2002 01:17

Urk, I must have been half asleep when I wrote those earlier messages... what I meant was that $DOCUMENT_ROOT isn't found on IIS. $PHP_SELF works just fine.

moebius
Obsessive-Compulsive (I) Inmate

From:
Insane since: Oct 2002

posted posted 10-27-2002 03:55

DL-44,

the reason why you cannot find $PHP_SELF anyway in the function is, is because it's not a function. It is a predefined constant. hope that helps.

digital.creme - the electronic swirl

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-27-2002 08:28

you should also check out getenv().
This functions get's enviroment variables, which not only
contain the url to the current script, but it's path and it's parameters (-> the stuff behind the ? in the url) as well.

so long,
Tyberius Prime

(edit: typo in the only place that counts. the function name.)

[This message has been edited by Tyberius Prime (edited 10-27-2002).]

« BackwardsOnwards »

Show Forum Drop Down Menu