PHP: Retrieve ID from a Simplified URL

Asked

Viewed 134 times

0

  • 2

    could simply do http://endereco/oficina.php/12345 already at once and take the value with $_SERVER['PATH_INFO'] (remembering to remove the bars from the string) - Or rename the home.php for your default page server name if it is no longer (usually index.html in Apache) and use $_SERVER['QUERY_STRING'] to get the number.

1 answer

1


Recommended and you use friendly url you can do as follows redirect all your traffic to index and manage the views according to the url passed example HTACCESS

RewriteEngine On
Options All -Indexes

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1

On your index page

//recupera a url
$GetURL = strip_tags(trim(filter_input(INPUT_GET, 'url', FILTER_DEFAULT))); 

//explode a url pela barra 
$URL = array_filter(explode('/', $GetURL));

you recover the value echo $URL[1];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.