Menu external link (no variable in URL)

General discussions about WebYep
Post Reply
DesignNorth
Rank 2
Rank 2
Posts: 57
Joined: Mon Apr 23, 2007 4:49 pm

Menu external link (no variable in URL)

Post by DesignNorth » Thu Sep 16, 2010 2:14 pm

You can (in a menu item) create an external link to a page using:
My Menu item Name#http://www.website.com

However WebYep sends a variable along with the URL or:
My Menu item Name#http://www.website.com?DOC_INST=5 (5 being the menu item)

The issue is this, if you want to link to a page within the same site using
My Menu item Name#my-other-webyep-page.php?DOC_INST=5

This ?DOC_INST=5 create a separate instance of the my-other-webyep-page.php so the original editable content cannot be seen. (you have to create duplicate content ~ or delete the original content and any link to the basic page)

Is there any way on NOT sending the ?DOC_INST=5 along with the link? Or are there any suitable workarounds?

johannes
Objective Development
Objective Development
Posts: 815
Joined: Fri Nov 10, 2006 4:39 pm
Contact:

Re: Menu external link (no variable in URL)

Post by johannes » Mon Sep 20, 2010 11:00 am

If the destination page does not want to make use of the instancing mechanism, you could insert this PHP code at the very beginning of the page (even before the WebYep Init Code!)

Code: Select all

<?php
   $_GET['DOC_INST'] = 0;
?>


That way any passed document instance ID will be deleted before the WebYep code can use it.

Please note that then the destination page cannot use a WebYep Menu itself - the page will always show the same content regardless which menu item was selected!

DesignNorth
Rank 2
Rank 2
Posts: 57
Joined: Mon Apr 23, 2007 4:49 pm

Re: Menu external link (no variable in URL)

Post by DesignNorth » Mon Jul 25, 2011 12:13 pm

I had a go with this but is did not work.

The page data returned remained at the DOC_INST value in the menu sending it.

Was the code

Code: Select all

<?php
   $_GET['DOC_INST'] = 0;
?>


Correct?

marcus
Objective Development
Objective Development
Posts: 170
Joined: Tue Nov 30, 2010 1:25 pm

Re: Menu external link (no variable in URL)

Post by marcus » Mon Jul 25, 2011 12:46 pm

DesignNorth wrote:I had a go with this but is did not work.

Where did you insert the code snippet? In the source page or the target?

DesignNorth wrote:Was the code

Code: Select all

<?php
   $_GET['DOC_INST'] = 0;
?>

Correct?

Yes, this is correct and will prevent the target page to process the DOC_INST.

DesignNorth
Rank 2
Rank 2
Posts: 57
Joined: Mon Apr 23, 2007 4:49 pm

Re: Menu external link (no variable in URL)

Post by DesignNorth » Mon Jul 25, 2011 4:00 pm

In the target page at the top of the page code

But the target page sent a ?DOC_INST=6 in the URL and that still displayed the instance of ?DOC_INST=6 in the target page and not the instance ?DOC_INST=0 (the equivalent of no variable)

DesignNorth
Rank 2
Rank 2
Posts: 57
Joined: Mon Apr 23, 2007 4:49 pm

Re: Menu external link (no variable in URL)

Post by DesignNorth » Mon Jul 25, 2011 4:13 pm

If I use

Code: Select all

<?php
  $DOC_INST = 10;
?>


At the top of the page code

The page always displays the variable in the URL ?DOC_INST=6 and not DOC_INST = 10

marcus
Objective Development
Objective Development
Posts: 170
Joined: Tue Nov 30, 2010 1:25 pm

Re: Menu external link (no variable in URL)

Post by marcus » Mon Jul 25, 2011 6:02 pm

DesignNorth wrote:If I use

Code: Select all

<?php
  $DOC_INST = 10;
?>

At the top of the page code

The page always displays the variable in the URL ?DOC_INST=6 and not DOC_INST = 10

There seems to be a misunderstanding. The correct code is

Code: Select all

<?php
   $_GET['DOC_INST'] = 0;
?>
and not

Code: Select all

<?php
  $DOC_INST = 0; // or 10
?>

It is a potentially dangerous configuration if your server automatically registers GET parameters as global variables (i.e. if a URL like "...?DOC_INST=0" would create a PHP variable $DOC_INST with the value 0)! Also, WebYep examines the contents of $_GET and not the corresponding auto-global variables.

Please note, that changing a GET parameter via PHP will not rewrite an URL. It will only change the value PHP uses.

However, the code snippet Johannes posted above will do the following (from the web servers point of view):
  • a link, generated by a MenuElement, like "http://www.example.com/page5.php?DOC_INST=6" is clicked
  • the browser sends this request (http://www.example.com/page5.php?DOC_INST=6) to the server
  • the server looks for the resource "page5.php" and loads it into memory
  • PHP kicks in and does some magic:
    • the URL is examined and everything after the "?" is made available to scripts as a special variable: $_GET
    • the page is processed by PHP and output is generated:
      If you insert the code snippet before the WebYep init code, it will change $_GET and WebYep will think that the DOC_INST parameter is zero (which is the same as no DOC_INST parameter at all).
      If you insert the code after the WebYep init code, it will also change $_GET, but at this time WebYep will already have fetched the original DOC_INST (i.e. 6) and therefore will show the contents of document instance #6.
  • the web server sends the output of PHP to the client (i.e. the web browser)

DesignNorth
Rank 2
Rank 2
Posts: 57
Joined: Mon Apr 23, 2007 4:49 pm

Re: Menu external link (no variable in URL)

Post by DesignNorth » Tue Jul 26, 2011 10:20 am

Found the issue the code was not before the WebYep Init Code ~ The Freeway action was not allowing this. I've hand coded it.

Post Reply