5

Hello Friends I want to get the Current Page Url instead of capturing root url of file

I want to capture Like this http://localhost/tester/

but coming like this

http://localhost/tester/views/inc/readcountry.php

I have tried like this but it's returning

$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]

localhost/tester/views/inc/readcountry.php

techiva.blogspot.com
  • 1,170
  • 3
  • 17
  • 37

4 Answers4

2

This one is working perfectly thanx alot

$_SERVER['QUERY_STRING']
techiva.blogspot.com
  • 1,170
  • 3
  • 17
  • 37
1

A little handy function I found somewhere else might help you out.

function url() {
  return sprintf(
    "%s://%s%s",
    isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
    $_SERVER['SERVER_NAME'],
    $_SERVER['REQUEST_URI']
  );
}

To use it:

echo url();
Peter
  • 8,776
  • 6
  • 62
  • 95
1

if you want the full url, try this:

<?php echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>

$_SERVER['HTTP_HOST'] - header from the current request, if there is one.

$_SERVER['REQUEST_URI'] - the URI which was given in order to access this page; for instance, '/index.html'.

$_SERVER['QUERY_STRING'] - it is your parameters and values in URL


My htaccess for MVC app:

RewriteEngine on

RewriteRule !.(js|gif|jpg|png|css)$ index.php

Plus in each directory (model, views, controllers) i putted htaccess too:

Deny from all

Kas Elvirov
  • 7,394
  • 4
  • 40
  • 62
0

Not knowing which is the point of the tree you need to stop the capture, I may suggest you to have a look at all the content of the [$_SERVER] array, dumping it, and at the php magic constants.