Aditya Shukla
Aditya Shukla

Reputation: 14225

Query string PHP

I have url xyz.com/s2d3f4 which redirects to xyz.com/index.php.I want to capture s2d3f4.i have tried query string and it does not work .Any suggestions on how to get that value?I am using http redirect.

Upvotes: 1

Views: 286

Answers (2)

aaz
aaz

Reputation: 5196

Every HTTP request is independent by design, so if you do a HTTP redirect (with header("Location: http://xyz.com/index.php") in PHP or RewriteRule ^ /index.php [R] in .htaccess) and the user sees http://xyz.com/index.php in the browser, then the original URL information is lost.

You can manually save it by

  • adding it to the query string: http://xyz.com/index.php?s=s2d3f4;
  • saving it in a session cookie (session_start etc.).

On the other hand, if you are actually doing an internal redirect, so the user still sees http://xyz.com/s2d3f4 in the browser but it's handled by index.php, then

  • $_SERVER['REQUEST_URI'] will hold the original URL (/s2d3f4);
  • you can also redirect with a query string (e.g., RewriteRule .* index.php?s=$0) and then that information will be available in $_REQUEST['s'].

Upvotes: 1

zod
zod

Reputation: 12417

Did you try PATH_INFO or 'ORIG_PATH_INFO

$HTTP_SERVER_VARS [deprecated] $_SERVER -- $HTTP_SERVER_VARS [deprecated] — Server and execution environment information

Anyway Try it

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

Upvotes: 0

Related Questions