-1

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

Desmond Dias
  • 51
  • 10

4 Answers4

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