4 Replies - 280 Views - Last Post: 23 January 2014 - 07:28 AM

#1 H_E_E  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 09-July 13

How to get address bar details

Posted 22 January 2014 - 09:34 AM

Hi I am trying to get address bar information the scenario is: A user writes www.example.com/sw.php to its Browser address bar but there is not a sw.php. I want to display ınvalid page message.moreover, if the address is www.example.com/images again the error message will be displayed,if the user writes www.example.com/sa.php user will be directed to sa.php. I have written this code but I get an error at line 8 and it does not work

I am waiting for your answers thanks
 <?php
$page = isset($_GET['page']) ? $_GET['page'] : 'sa';
$page = isset($_POST['page']) ? $_POST['page'] : 'sa';
require $page . '.php';

$pages = array("sa");

if(in_array($page, $pages){
 echo "header( Location: "<? $page. '.php' ?>" )";
else    
    die('Invalid page');
		}
?>



Is This A Good Question/Topic? 0
  • +

Replies To: How to get address bar details

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: How to get address bar details

Posted 22 January 2014 - 09:49 AM

you’re not understanding how HTTP requests work and what PHP’s $_GET/$_POST arrays mean.

$_GET contains the URL parameters, not the URL!

non-existing URLs don’t even make it to PHP. they are caught by the web server (e.g. the Apache web server)

details about the current URL can be found in the $_SERVER array.


some articles for information:
- HTTP
- Path Translation
- $_SERVER
- $_GET
- PHP’s URL Functions
Was This Post Helpful? 0
  • +
  • -

#3 H_E_E  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 09-July 13

Re: How to get address bar details

Posted 22 January 2014 - 10:56 AM

Thanks a lot,articles where very helpful

View PostDormilich, on 22 January 2014 - 09:49 AM, said:

you’re not understanding how HTTP requests work and what PHP’s $_GET/$_POST arrays mean.

$_GET contains the URL parameters, not the URL!

non-existing URLs don’t even make it to PHP. they are caught by the web server (e.g. the Apache web server)

details about the current URL can be found in the $_SERVER array.


some articles for information:
- HTTP
- Path Translation
- $_SERVER
- $_GET
- PHP’s URL Functions

This post has been edited by H_E_E: 22 January 2014 - 10:57 AM

Was This Post Helpful? 0
  • +
  • -

#4 AfterBurner66  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 116
  • Joined: 02-August 08

Re: How to get address bar details

Posted 23 January 2014 - 07:26 AM

All you describe and more, can be done in web server level in a more safe and secure way (redirections, excluding directories etc.)
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: How to get address bar details

Posted 23 January 2014 - 07:28 AM

I would even go as far as saying that it cannot be done in PHP.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1