0

On my server i have everything redirected to index.php I have to My index.php works as user inputs url

http://ip:80/index.php
then it executes php script as follows

'$input = trim($_SERVER["REQUEST_URI"], "/")

if(){statement}else{statement}'

I want to edit that index file so it executes 2 different if statements 
For example if user inputs this url  http://ip:80/server1/index.php
then it executes statement 1

`if(){statement 1}
if(){statement 2}
else{statement}`

if user inputs url as http://ip:80/server2/index.php then it executes statement2

`if(){statement 1}
if(){statement 2}
else{statement}'
Cammy
  • 1
  • 2

1 Answers1

0

First you'll need to redirect everything to your index.php. On most Apache server, you can set the direction with a .htaccess file, like so :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Next, you simply have to check the $_SERVER["REQUEST_URI"] value, for example :

$input = $_SERVER["REQUEST_URI"];
if (strpos($input, 'server1/')!==false) {
      // statement 1
} else if (strpos($input, 'server2/')!==false) {
      // statement 2
} else {
      // default statement
}

I suggest you read about URL rewriting for more information.

E-telier
  • 766
  • 5
  • 15