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

Link to comment
Share on other sites

 

<?php

echo $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];

?>

 

Thats just doing the same as

 

<?php echo $_SERVER['REQUEST_URI']; ?>

 

?

 

EDIT: Because my stuff is in a folder, I'm getting /thingy/test.php?a=b or whatever with that :/

Link to comment
Share on other sites

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;

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.