Test Which Page User Currently On

Discussion in 'Customization & add-ons' started by karyng01, Jul 19, 2012.

  1. karyng01

    karyng01 aMember Pro Customer

    Joined:
    Jul 30, 2008
    Messages:
    71
    Does anyone know a way to test which page (URL) a user is currently on? I want to test for viewing a certain page and then add a menu item if that condition is true or remove a menu item if that condition is false.

    Thanks if anyone knows an API function or PHP code that can return the current page being viewed.

    Aly
  2. karyng01

    karyng01 aMember Pro Customer

    Joined:
    Jul 30, 2008
    Messages:
    71
    In the site.php file you can use a variable (named as you wish) to return the current page's full hyperlink URL, in this example the variable is named $userlink

    PHP:
    $userlink "http://" $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];  //Return current hyperlink of page being rendered
    Here is an example of testing you can do using this information, to find all pages that have 'helpdesk' in their URL, what you then do from their with this information is up to you.

    PHP:
    $userlink "http://" $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];  //Return current hyperlink of page being rendered
    $helpdesk 'helpdesk';  //Set variable value
    $helpdeskexists strpos($userlink$helpdesk);  //Search for presence of value 'helpdesk' in current page hyperlink
  3. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Other useful methods:
    PHP:
    Am_Di::getInstance()->request->getModuleName(); // amember module name, for example 'default'
    Am_Di::getInstance()->request->getControllerName(); // amember controller name, for example 'member'
    Am_Di::getInstance()->request->getActionName(); // action name, for example 'index'
    Am_Di::getInstance()->request->getParam('xx'); // if url ends with ?xx=22, will return 22
     
     
  4. karyng01

    karyng01 aMember Pro Customer

    Joined:
    Jul 30, 2008
    Messages:
    71
    Thanks Alex, very useful functions.

Share This Page