Jump to content

[SOLVED] Getting the URL of the current page


marklarah

Recommended Posts

Hi

 

I need to get the the current page and store it as a variable. I realize I could do something like

<?php echo basename($_SERVER['SCRIPT_FILENAME']); ?>

 

but if the current page was page.php?a=b or whatever, that would of course only tell me page.php, and I would like to be able to store page.php?a=b.

 

So currently, I am using this

 

<?php
$urlarr = explode('/', $_SERVER['REQUEST_URI']);
$page = count($urlarr)-1;
echo $urlarr[$page];
?>

 

but it seems terribly inefficient for something that is probably rather simple. How would I do this in a quicker way?

 

Thanks

even better way.

 

GAMES ARE OVER BACK TO WORK LOL

<?php 

$path="/redarrow/the_real_way.php?1=yes_you_no"; 

preg_match("/[a-z]{0,100}\.?[code=php:0].*/",$path,$matched); 

$result=implode(" ",$matched);

echo $result;

?>

 


<?php 

$path=$_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING']; 

preg_match("/[a-z]{0,100}\.?[code=php:0].*/",$path,$matched); 

$result=implode(" ",$matched);

echo $result;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.