tags:

views:

58

answers:

4

Hi all, I'm building a website, and i need to know the actual page address in which the user is in, in order to take users in the same page after login. The problem is that every page is generated from variables passed by url and query string, so I dont't know how to recover every variable and assign to it the correct value. How to recover variables name and assign them the correct values?

Thanks

lore (sorry for my English)

+3  A: 

echo $_SERVER['REQUEST_URI']?

binaryLV
thank you for the answer, I solved with a foreach loop on $_POST array.
lore3d
hmm... $_POST does not contain variables from URL ($_GET does).
binaryLV
+1  A: 
<?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;
}
?>

You can now get the current page URL using the line:

<?php
  echo curPageURL();
?>

Is this what you are after?

Russell Dias
I doubt that. looks like he is looking for something like $_SERVER["REQUEST_URI"], as protocol and host remain the same.
Col. Shrapnel
thank you for the answer, I solved with a foreach loop on $_POST array.
lore3d
A: 

Are you looking for this (page name)?

echo basename($_SERVER['REQUEST_URI']);
Sarfraz
this could bring some surprises when human readable urls is used.
Col. Shrapnel
thank you for the answer, I solved with a foreach loop on $_POST array.
lore3d
A: 

Try $_SERVER['SCRIPT_URI']

Alexei
SCRIPT_URI is not always defined. It's not even mentioned in http://lv.php.net/manual/en/reserved.variables.server.php (which is a list of elements in $_SERVER). Some say that PHP must be run as CGI to have SCRIPT_URI defined.
binaryLV
thank you for the answer, I solved with a foreach loop on $_POST array.
lore3d