Results 1 to 6 of 6

Thread: newbie to php...if url contains x then do y

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Beans
    55
    Distro
    Ubuntu 10.10 Maverick Meerkat

    newbie to php...if url contains x then do y

    Ok,

    Wasn't sure where to turn. I have basically no php experience. While being a novice I do have a basic understanding of programming - just no experience(meaning if I see the code I can figure out what it does and modify it but don't know enough to write from scratch

    Ok, to the point - I am trying to make my links for my simple html/css site in an include file so I can easily update/add/remove links and change it for all pages. The problem is I also have classes so that when on one page that tab is all caps and a different color etc. In an include file though I will need to code it to do that.

    Here is the current include file:
    Code:
    <ul>
    <li class="normal"><a href="ContactUs.shtml"><img src="images/ContactUs.jpg" /></a></li>
    <li class="normal"><a href="Upcoming.shtml">Upcoming Auctions</a></li>
    <li class="normal"><a href="Seller.shtml">Seller Benefits</a></li>
    </ul>
    I am looking for something that would say - If current url == "ContactUs.shtml" then class="current"

    Basically determine what page is active and make that class the "current" class.

    Any help?
    Thanks in advance!

    Carade
    www.alexjonespodcasts.com - the other side of news

    Precision M6300 - Core 2 Duo - 8GB RAM
    Ubuntu 10.10 x64 bit

  2. #2
    Join Date
    Nov 2010
    Beans
    1

    Re: newbie to php...if url contains x then do y

    Are you looking for HttpMessage::getRequestUrl ?
    Last edited by l0rb; November 11th, 2010 at 08:09 PM. Reason: typo

  3. #3
    Join Date
    Apr 2008
    Beans
    55
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: newbie to php...if url contains x then do y

    After some googling this is what I came across:

    Code:
    <?php if ($_SERVER['REQUEST_URI']=='/Upcoming' ) {$Upcoming = 'active'} else {}? {echo $Upcoming} ?>
    I declared the variable in advance to be 'normal'
    Code:
    <?php $Upcoming = 'normal' ?>
    and the code should change the variable to be 'active' if the url contains '/Upcoming'... I put the echo $Upcoming in there for debugging to see if it is changing that variable. Unfortunately it is changing that variable no matter what the url contains.

    I also have not figured out how to take the
    Code:
    <li class="active/normal">
    to insert the variable so that it would be
    Code:
    <li class="$Upcoming">
    Can someone explain how to implement the php variable into that html/css statement?

    thanks
    www.alexjonespodcasts.com - the other side of news

    Precision M6300 - Core 2 Duo - 8GB RAM
    Ubuntu 10.10 x64 bit

  4. #4
    Join Date
    Jan 2007
    Beans
    41

    Re: newbie to php...if url contains x then do y

    I think the easiest way, or the way I tend to use is like this;

    You can declare the value of a variable in a url via ?variable=value

    For example;

    index.php?page=this

    Would be able to be retrieved via php by;
    PHP Code:
    <?php

    $page 
    $_GET['page'];

    ?>
    So you'd do something like:

    PHP Code:
    <li class="<?php echo $page?>">adasdas</li>
    It's a bit vague, but hopefully reading this will give you a better idea and something to toy around with.
    Last edited by Mmmbopdowedop; November 12th, 2010 at 06:54 PM.

  5. #5
    Join Date
    Apr 2008
    Beans
    55
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: newbie to php...if url contains x then do y

    Thank you so much sir!

    That is exactly the tip I needed. Got it all squared away with your get method and set up if statements and it is working like a charm.

    5 stars for your answer and a million dollars - well, maybe not a million dollars.

    * * * * * 5 STARS * * * * (now 10!)
    www.alexjonespodcasts.com - the other side of news

    Precision M6300 - Core 2 Duo - 8GB RAM
    Ubuntu 10.10 x64 bit

  6. #6
    Join Date
    Nov 2010
    Beans
    5

    Re: newbie to php...if url contains x then do y

    Hey caradeporra could you share the code you came up with, I'm trying to work a very similar thing, thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •