-1

Let my site url be http://example.com .

Suppose if the user is entering the url http://example.com/profile_103.php , i need to display the profile of user having an id 103 and the file profile_103.php does not exist. I need to get the values extracted from the file name that the user types .

How can i do this in php ?

Anuraj TS
  • 19
  • 4

1 Answers1

0

Quick & dirty solution with Apache & PHP for http://example.com/profile_103.php:

  1. Make sure you have RewriteEngine on in Apache
  2. Make an .htaccessfile with the following content:

    RewriteEngine on
    RedirectMatch 403 /..*$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php

  3. Content of index.php is:

    $userId = str_replace('.php', '', str_replace("/profile_", '', $_SERVER['REQUEST_URI']));
    echo $userId;

ialbescu
  • 161
  • 1
  • 4