i want to retreive values passed in the url without using the GET method
i.e
http://example.com?id=10
but instead using something like this
http://example.com/10
Asked
Active
Viewed 466 times
-1

Desmond Dias
- 51
- 10
-
why you don't want to use GET method? – Gitesh Purbia Jan 10 '18 at 06:43
-
What you want to use is used to link to a different file, so it won't be possible to use it as a file. If you don't want to see the `?id=10` in your url, then use post method. – Geshode Jan 10 '18 at 06:43
-
if you want that types of url, in core it will be tricky, better use any framework of php like codeigniter. – Gitesh Purbia Jan 10 '18 at 06:44
-
1With PHP or JS ?? – Abdulla Nilam Jan 10 '18 at 06:44
-
The GET method is used by clients to fetch data from an HTTP server. It has nothing to do with how parameters are passed in the URL. Your question seems to be about changing the URL format. Please clarify. – Roland Weber Jan 10 '18 at 06:46
-
Try this link: https://stackoverflow.com/questions/8469767/get-url-query-string – Kannan K Jan 10 '18 at 06:46
-
seems you are talking about URL rewriting. Thats something else. – Rotimi Jan 10 '18 at 07:03
4 Answers
1
You may try explode() with end() in php
Example :-
<?php
$url = explode('/',$_SERVER['REQUEST_URI']); // Ex :- http://example.com/10
echo end($url); // get params form url 10

Aman Kumar
- 4,533
- 3
- 18
- 40
0
if you want to get 10
from url without using GET
method.
//get complete url
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
//using explode function convert into array
$url = explode('/', $url);
//print your desired array index
echo $url[2];

Bilal Ahmed
- 4,005
- 3
- 22
- 42
0
JavaScript itself has nothing built in for handling query string parameters.
In a (modern) browser you can use the (experimental at time of writing) URL object;
var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Run code snippetCopy snippet to answerExpand snippet For older browsers, you can use this polyfill or the code from the original version of this answer that predates URL:
You could access location.search, which would give you from the ? character on to the end of the URL or the start of the fragment identifier (#foo), whichever comes first.
Answer By Quentin How to get the value from the GET parameters?

TarangP
- 2,711
- 5
- 20
- 41
0
If PHP
$uri = explode('/', $_SERVER['REQUEST_URI']);
print_r($uri); # Array ( [0] => http: [1] => [2] => example.com [3] => 10 )
echo $uri[3]; # 10

Abdulla Nilam
- 36,589
- 17
- 64
- 85