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

Current Page URL

Lu Jia

Active member
#1
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 :)
 

borbole

Well-known member
#4
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
$paths = XenForo_Application::get('requestPaths');

XenForo_Application::get('requestPaths'); returns an array with the requested data;)
$paths['fullUri'] should include the link
 
#12
What about it? That is common knowlege for eveyone familiar with php.
Then it's a sign that you're not familiar with php or you don't want to read the page.

$_SERVER[‘SCRIPT_NAME’] contains the /group/ directory and the script name (index) and it should have called it.
$_SERVER[’SCRIPT_NAME’]
In all cases here we were returned only the file name /example/index.php regardless of if it was typed, not typed, or anything was appended to it.
 

borbole

Well-known member
#13
Then it's a sign that you're not familiar with php or you don't want to read the page.
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 ;)
 

borbole

Well-known member
#15
lol
it hurts that you removed the like.:( you're really mature..)

it doesn't contain /group/index.php
check your testpage: http://www.forumservices.eu/getlink/getlink.php/test?1 wheres there /test ??? ;)

Nevermind, you're welcome to use your false code...
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.