Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Retrieving complete URL from page ($_GET[?]?)

Retrieving complete URL from page ($_GET[?]?)

Locked

Views: 2,889

Results 1 to 17 of 17
This thread is locked. New replies are disabled.
24 Aug 2010, 5:19 PM
#1
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Retrieving complete URL from page ($_GET[?]?)

I'm working on a mod to highlight the current page link in ez-pages menus, and used $_GET['url'] to compare the page url with the link url. This seemed to be successful in initial trials, but now doesn't work, and my research seems to show that it doesn't exist.

What can I use to retrieve the complete current page URL? This may be a case of not using the right term to search with, as I would think it ought to be possible.
Where can I find a more or less complete list of $_GET[] fields? Or does such a list exist? I have looked in the forum, the wiki and my site's DTK so far.

24 Aug 2010, 5:39 PM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Retrieving complete URL from page ($_GET[?]?)

$_GET without square brackets or an index will return the entire array of parameters being passed. Does that help?

24 Aug 2010, 5:50 PM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Retrieving complete URL from page ($_GET[?]?)

Thanks for that! It might help, though reassembling all the right parameters in the right order would be a real pain. I don't suppose you know if the parameters are ordered in the same sequence they appear in the address bar? If they are, an implode() might possibly work? Or maybe not, as there are different delimiters between different parts of the URL, and things like "main_page=" would also have to be added back in.

24 Aug 2010, 5:53 PM
#4
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Retrieving complete URL from page ($_GET[?]?)

The $_GET array is associative, so the order doesn't matter. URLs don't care about the order either.

24 Aug 2010, 5:57 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Retrieving complete URL from page ($_GET[?]?)

The point is that I have to compare a link string which could have a huge number of different components with the page URL it might have called, and it seems a nightmare to compare all possible link elements with URL elements.

24 Aug 2010, 5:57 PM
#6
skipwater avatar

skipwater

Totally Zenned

Join Date:
Jun 2008
Location:
Washington, DC
Posts:
775
Plugin Contributions:
1

Re: Retrieving complete URL from page ($_GET[?]?)

I have used $_SERVER['REQUEST_URI']

Skip

24 Aug 2010, 6:01 PM
#7
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Retrieving complete URL from page ($_GET[?]?)

Are you looking maybe for the zen_get_all_params() function which is used to rebuild a URL excluding any parameters passed in an array

Example usage:

zen_href_link($current_page_base, zen_get_all_get_params(array('currency','language')))
```to strip the language and parameter params and give back what's left of the page's URL.
24 Aug 2010, 6:01 PM
#8
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Retrieving complete URL from page ($_GET[?]?)

AHA! I knew I had seen something that would show that. That's what it was. Thank you so much!

Since the ez-page link will be in the form of a complete URL, comparing that with the actual page's complete URL will be easiest. It will be okay if the page URL runs longer than the link.

24 Aug 2010, 6:02 PM
#9
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Retrieving complete URL from page ($_GET[?]?)

If this is for ezpages, don't you care only about the "main_page" and "page" parameters?

24 Aug 2010, 6:10 PM
#10
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Retrieving complete URL from page ($_GET[?]?)

Oh I think I see. You're refering to to the URLs of EZ-Pages themselves, but to the URLs that they forward onto?

24 Aug 2010, 6:17 PM
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Retrieving complete URL from page ($_GET[?]?)

Correct. Getting the active ez-page link to highlight was trivial, but the internal link pages are another matter.

24 Aug 2010, 9:41 PM
#12
berserker avatar

berserker

Totally Zenned

Join Date:
May 2006
Posts:
712
Plugin Contributions:
0

Re: Retrieving complete URL from page ($_GET[?]?)

Hello,

Im actually doing the same thing but for my custom navigation. I managed to get the category link button to be highlighted by using $current_category_id =='1 (or any number of the category)'. The problem is that this also highlights the home link button. Im not sure why this is. I have $current_page_base =='index' for the home link button. Is this correct? Any help would be great.

Thanks

24 Aug 2010, 10:00 PM
#13
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Retrieving complete URL from page ($_GET[?]?)

The trouble with $current_page_base =='index' is that category and product listing pages also are 'index'. You need a more particular method. Actually, $this_is_home_page is effective for that.

I would need to see what you have to offer more specific advice on other links.

24 Aug 2010, 10:02 PM
#14
berserker avatar

berserker

Totally Zenned

Join Date:
May 2006
Posts:
712
Plugin Contributions:
0

Re: Retrieving complete URL from page ($_GET[?]?)

Thanks a lot!!! That sorted it :)

19 Nov 2010, 10:34 PM
#15
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Retrieving complete URL from page ($_GET[?]?)

I thought I had this mod complete, with internal links in the ez-pages menus highlighting correctly when active, but have discovered a situation that I can't explain.
This is the function:```php
//call as active_page_class($var_linksList[$i]['id'],$var_linksList[$i]['altURL']);
function active_page_class($ezpid,$alturl) {
global $this_is_home_page;
$active = '';
if($_GET['main_page'] == 'page') {
$active = ($_GET['id'] == $ezpid)? ' class="activeEZPage"': '';
}elseif($alturl) {
$alturl = str_replace(HTTP_SERVER . DIR_WS_CATALOG,'/',$alturl);
$active = ((strstr($_SERVER['REQUEST_URI'],$alturl) and !strstr('/index.php?main_page=index',$alturl)) or ($this_is_home_page and strstr('/index.php?main_page=index',$alturl)))?' class="activeILPage"': '';
}
return $active;
}

Debug output gives this:
uri:/fr-zc139gfresh/index.php?main_page=index&cPath=3_10 
alt:/index.php?main_page=index&cPath=3_10

The 
$active = ((strstr($_SERVER['REQUEST_URI'],$alturl)
should be finding the relative link ($alturl) in $_SERVER['REQUEST_URI']. It is clearly there when the strings are echoed, but echoing the strstr() as shown gives null. I am at a loss to understand why these two apparently identical string parts are not being found to match.

I observe that these links contain an & while none of the correctly functioning ones do. Could this be related to the v1.3.9g HTML bug? (My local test site is currently v1.3.9g.) I have not edited anything in admin beyond the essentials.
One of the links which I opened to set the footer display (possibly more than once) now shows in view source
/index.php?main_page=index&amp;cPath=21">Gift Certificates</a>
while the other shows the correct
/index.php?main_page=index&cPath=3_10">Action DVDs</a>
Neither of them highlights; of course, the defective one does not link correctly.
20 Nov 2010, 7:06 PM
#16
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Retrieving complete URL from page ($_GET[?]?)

Got it.

The strings are not identical because the ZC link has the ampersand coded as & while the URI is just &. It doesn't show up when echoed to the page, but does when echoed to an HTML comment and looked at in view source.

20 Nov 2010, 7:37 PM
#17
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Retrieving complete URL from page ($_GET[?]?)

Amended line:

    $alturl = htmlspecialchars_decode(str_replace(HTTP_SERVER . DIR_WS_CATALOG,'/',$alturl));