1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Current Page URL

Discussion in 'XenForo Development Discussions' started by Lu Jia, May 25, 2011.

  1. Lu Jia

    Lu Jia Active Member

    Hi all,
    I want to ask you if is there a way with xenforo's api to get the current page's url

    At the moment i'm using this function:
    PHP:
    function curPageURL() {
    $pageURL 'http';
    if (
    $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    $pageURL .= "://";
    if (
    $_SERVER["SERVER_PORT"] != "80") {
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return 
    $pageURL;
    }
    echo 
    curPageURL();
    But it will return an error. It can be fixed if u comment the https line:
    PHP:
    function curPageURL() {
    $pageURL 'http';
    // if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    $pageURL .= "://";
    if (
    $_SERVER["SERVER_PORT"] != "80") {
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return 
    $pageURL;
    }
    echo 
    curPageURL();
    Is there an other way to do it?
    Thanks in advance :)
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Moved from development tutorials to development questions.
     
  3. Lu Jia

    Lu Jia Active Member

    sorry, my fault ^^'
     
  4. borbole

    borbole Well-Known Member

    Can you try this? It will get the full current page 's url (the domain name, script name, url parameters and any variation)

    PHP:
    $serverprotocol strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')  === FALSE 'http' 'https';

    $hostname    $_SERVER['HTTP_HOST'];
    $scriptname  $_SERVER['SCRIPT_NAME'];
    $parameters  $_SERVER['QUERY_STRING'];

    $currentpageURL $serverprotocol '://' $hostname $scriptname '?' $parameters;

    echo 
    $currentpageURL;
     
  5. ajnos

    ajnos Member

    $paths = XenForo_Application::get('requestPaths');

    XenForo_Application::get('requestPaths'); returns an array with the requested data;)
    $paths['fullUri'] should include the link
     
    Lu Jia likes this.
  6. Lu Jia

    Lu Jia Active Member

  7. Lu Jia

    Lu Jia Active Member

    Thanks that's what I'm looking for :D
     
  8. borbole

    borbole Well-Known Member

  9. ajnos

    ajnos Member

  10. borbole

    borbole Well-Known Member

  11. Lu Jia

    Lu Jia Active Member

    I don't know but it doesn't work for me, maybe the problem is that 'group' is not a physical folder but a route prefix
     
  12. ajnos

    ajnos Member

    Then it's a sign that you're not familiar with php or you don't want to read the page.

     
  13. borbole

    borbole Well-Known Member

    That is exactly what I said. That it contains the directory and the script name which in this case was the ....../group/index.php

    Maybe it is a sign that you should read better before jumping into conclusions ;)
     
  14. ajnos

    ajnos Member

  15. borbole

    borbole Well-Known Member

    What are you talking about? What test? The code I posted above gets the current page url. Just like the OP asked. And the /group/index.php was for the example posted above by the OP.

    And there is nothing false about that code. But arguing with you is pointless. You have that I know better and the rest knows nothing aura.
     
  16. Lu Jia

    Lu Jia Active Member

  17. ajnos

    ajnos Member

    sorry
     
  18. Anoop

    Anoop New Member

    I think this will be getting by using {$requestPaths.fullUri} from the pages.
     
    Amor and nttruong like this.

Share This Page