Page 1 of 1

How do I detect the URL in the address bar using PHP?

Posted: Thu Oct 26, 2006 2:48 am
by adders
Hello All

I'm looking to decet the URL in the address bar of the browser and when it contains a url specified by the $nodisplay variable the code mosLoadModules ( 'header', -2); will not run. Basically I don't know how to reference the URL.

I think I've made some headway - can anyone fill in the blanks (blanks = ???????????????).

So I need to add code that detects the current URL in the place of the ?????????????.

Just to warn you there may be other errors too.

I use Joomla CMS by the way and for what I want to do the module publishing functions aren't sufficient, the frontpage url is just an example I actually have to stop code running for specific pages within individual components.

Code: Select all

<html> 
   <head> 
      <?php 
           $url = ?????????????????; 
           $nodisplay = "index.php?option=com_frontpage&Itemid=1"; 
       ?> 
   </head> 
   <body> 
      <div id="header"> 
         <?php 
            if 
            ( $nodisplay == $url ) 
            { 
            return; 
            } 
            else 
            { 
            mosLoadModules ( 'header', -2); 
            } 
            ?> 
         </div> 
    </body> 
</html>

Hope someone can help

Cheers

Paul

Posted: Thu Oct 26, 2006 3:15 am
by kaszu

Code: Select all

$url = substr($_SERVER['REQUEST_URI'],1);
But it won't work if there will be additional parameter, different case or order.

My suggestion would be:

Code: Select all

$pos = strpos($_SERVER['REQUEST_URI'], '?');
    if ( $pos === false or !isset($_GET['option']) or !isset($_GET['Itemid']))
    {
        $url = '';
    } else {
        $url = substr($_SERVER['REQUEST_URI'],1, $pos); 
        $url .= 'option='.$_GET['option'].'&Itemid='.$_GET['Itemid'];
    }
Tried not to change anything else. Haven't tested, but it should work (if instead of "Itemid" will be "itemid" then it won't work).

Posted: Thu Oct 26, 2006 3:59 am
by timvw
My http client doesn't have an address bar...

Posted: Thu Oct 26, 2006 4:00 am
by adders
Thanks Kaszu - it's been bugging me for a while.

I've give it a go, there shouldn't be any additional parameters.

Cheers

Adders

Posted: Thu Oct 26, 2006 4:08 am
by adders
Hello Again

Thought I'd let people that Kaszu's advice worked.

Now when $nodisplay matches the current URL the code I want skipped isn't run, cool.

By the way does any one know how to code this up for more than one URL or URL's that match a certain pattern?

So that the code doesn't run on several pages.

Code: Select all

<head>
$url = substr($_SERVER['REQUEST_URI'],1);;
$nodisplay = "vos_new/index.php?option=com_frontpage&Itemid=1";
</head>
<body>
   <?php 
				if ($nodisplay == $url) 
					{ 
					} 
				else 
					{ 
					mosLoadModules ( 'header', -2); 
					}  
   ?>
</body>
Cheers

Adders

Posted: Thu Oct 26, 2006 7:47 am
by feyd

Posted: Thu Oct 26, 2006 8:43 am
by adders
Cheers mate - I'll check it out when I get a chance tomorrow.