473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to check current url and specify #currentlink?

I use #currentlink in a nav list of links to indicate which page is
currently being viewed.

The code in the nav list looks like this:

<p><a href="index.php">Home Page</a></p>
<p><a href="contact.php">Contact</a></p>
<p><a href="tech.php#tech01">tech01</a></p>
<p><a href="tech.php#tech02">tech02</a></p>
<p><a href="tech.php#tech03">tech03</a></p>

The problem is that there are 3 named anchors on the tech.php page. If
there were no named anchors, and only one link to tech.php, I could do this:

<p><span id="currentlink"><a href="tech.php">tech</a></span></p>

That would change the color of the link as desired. But because there are
multiple links on the same page, I can't do this. So I need some php to
check the current url (I think) and echo the appropriate currentlink (again,
a guess) based on the url - so only the link referencing the current named
anchor will change color.

Here's some pseudo code:

<?php
/*
if ( current url = "tech.php#tech01" )
{
make "tech.php#tech01 the currentlink
}
elseif ( current url = "tech.php#02" )
{
make "tech.php#tech02 the currentlink
}
... and so on
*/
?>

Does this sound like the right way to go about this? How do I check the
current url, and how do I then get php to say the equivalent of :

<p><span id="currentlink"><a
href="tech.php#thisLink">thisLink</a></span></p>

Any help is appreciated!

By the way, the css code looks like this:

#currentlink a:link { color:#CC0000; }
#currentlink a:visited { color:#CC0000; }
#currentlink a:hover { color:#CC0000; }
#currentlink a:active { color:#CC0000; }
Jul 17 '05 #1
3 6957
> Does this sound like the right way to go about this? How do I check the
current url, and how do I then get php to say the equivalent of :


Here's half the puzzle. But how to set currentlink? - in standard html it
looks like this:
<p><span id="currentlink"><a href="tech.php#02">tech02</a></span></p>

<?php
$here = $_SERVER["PHP_SELF"];
//echo $here;
if ( $here == "/tech.php" )
{
//designate tech.php as currentlink
}
else if ( $here == "/tech.php#tech01" )
{
//designate tech.php#tech01 as currentlink
}
else if ( $here == "/tech.php#tech02" )
{
//designate tech.php#tech02 as currentlink
}
?>
Jul 17 '05 #2
Nonr of this returns the current named anchor - is it possible to get named
anchor with php? it appears in my browser's address window, but I can't
seem to find it in any variable.

$url = parse_url($_SERVER['PHP_SELF']);
$scheme = ($url[scheme]);
$host = ($url[host]);
$port = ($url[port]);
$user = ($url[user]);
$pass = ($url[pass]);
$path = ($url[path]);
$anchor = ($url[fragment]);
echo $scheme." = scheme<br>";
echo $host." = host<br>";
echo $port." = port<br>";
echo $user." = user<br>";
echo $pass." = pass<br>";
echo $path." = path<br>"; //==>> * * * this is the only thing i get
echo $anchor." = anchor<br>";

$url = parse_url($_SERVER['QUERY_STRING']);
$scheme = ($url[scheme]);
$host = ($url[host]);
$port = ($url[port]);
$user = ($url[user]);
$pass = ($url[pass]);
$path = ($url[path]);
$anchor = ($url[fragment]);
echo $scheme." = scheme<br>";
echo $host." = host<br>";
echo $port." = port<br>";
echo $user." = user<br>";
echo $pass." = pass<br>";
echo $path." = path<br>";
echo $anchor." = anchor<br>";
Jul 17 '05 #3
In article <gr*****************@newssvr27.news.prodigy.com> , deko wrote:
Nonr of this returns the current named anchor - is it possible to get named
anchor with php?


AFAIK it's not possible.

--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
1
by: Imayakumar | last post by:
Hi, I am using VSS through CommandLine. I have a problem in Checking Out a file. Whenever I invoke the following command, "SS Checkout File2.txt -YAdmin " the file gets checked out to the current...
2
by: Ken Durden | last post by:
I'm setting up an interface where clients must perform external locking before calling certain commands. I do this to force them to specify the duration the action they performed must persist...
5
by: LL | last post by:
Hi, Where is the best place to check the session's object, if it's null, then redirect the user to login page? put into every page's load event? Thanks.
41
by: Mountain Bikn' Guy | last post by:
What is the current preferred way to save user preferences in dotnet? Is the registry the right place to do this? Can anyone recommend a good article (or book) for this topic? Thanks.
7
by: Sameh Ahmed | last post by:
Hello there IsInrole gives ya the means to check if the current or impersonated user belongs to a specific windows role or group. is there a way to do the same without using ADSI to check if...
3
by: namewitheldbyrequest | last post by:
"The XML element 'EnableTheming' from namespace 'http://tempuri.org/' is already present in the current scope" I created a Web Service: I imported System.Data.SqlClient so I could access SQL...
2
MattFitzgerald
by: MattFitzgerald | last post by:
Hi hope some one can help I have 2 questions:- Question 1) When saving a file in access to excel how do I specify current date Question2) When saving a file in access to excel how do I specify...
12
by: foolsmart2005 | last post by:
There are 10 webpages on the host, e.g. 001.html, 002.html, 003,html, 004.html, ......010.html I want to check whether the page is the last page. How can I do. In the index.html -Go to last...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.