user56489870 user56489870 - 23 days ago 5
PHP Question

what do I call the trailing value after last slash in a url and how to get it in php

I'm new to PHP and web, and I was wondering, in some URLs what do we call the last string value after the last slash. for example "abc123" in this url

URL 1

http://www.example.com/folder1/abc123




I know about the URL
parameters
that is exist after a
?
question mark and how to get it inside my PHP scripts, like

URL 2

http://www.example.com/folder1/phpscript1.php?name=mike&age=24


when the browser requests this resource from the web server, the web server (Apache for example) are going to invoke the php module which will try to parse
phpscript1.php
giving him the data he needs to work. in this example I can see the
name
and
age
parameters inside my phpscript1.php file like this

$name = $_GET['name'];
$age= $_GET['age'];




Q1- In URL1 what do I call "abc123" ? parameters ?

Q2 In URL1 how the web server is going to deal with this request? will it try to find a resource that is called
"/folder1/abc123"
and just send it blindly to the browser ? for example if I have a file on the server that has the name
"abc123"
inside the folder
"/folder1/"
, is it going to be sent to the browser ?

Q3 in URL1 how do I get the value "abc123" inside my PHP scripts? or even which is more important, which PHP script are going to be invoked by the PHP module to handle this request?

Answer

Q1- In URL1 what do I call "abc123" ? parameters ?

This is simply part of the path.

Q2 In URL1 how the web server is going to deal with this request? will it try to find a resource that is called "/folder1/abc123" and just send it blindly to the browser ? for example if I have a file on the server that has the name "abc123" inside the folder "/folder1/", is it going to be sent to the browser ?

It depends on how your server is configured. Apache will look for the default document, which is defined in the httpd.conf file. It will likely look first for a file called index.html or index.php, but you can set it to look for other things, too. It will likely assume that the part after the last / is the filename, unless it's a folder name.

Q3 in URL1 how do I get the value "abc123" inside my PHP scripts? or even which is more important, which PHP script are going to be invoked by the PHP module to handle this request?

You should look up the $_SERVER superglobal. It will likely have what you're looking for:

http://php.net/reserved.variables.server