詳細検索

Get PATH_INFO and assign to hidden

Avatar
by すがピー
2 min read
Tags php

Get PATH_INFO and assign to hidden
Translated from 日本語 • View original

If you want to attach a parameter to the URL and send it as a GET,

http://www.example.com/?param0=aaa&param1=bbb

When you give it to me and receive it,

$param0 = $_GET['param0'];
$param1 = $_GET['param1'];

or

$param0 = $_REQUEST['param0'];
$param1 = $_REQUEST['param1'];

It is common to do so, but as follows,

http://www.example.com/aaa/bbb/

and receive the

$param = split("[/\.]", $_SERVER["PATH_INFO"]);

If so, "aaa" is assigned to $param[0] and "bbb" is assigned to $param[1].

Now, if you try to do this in WordPress, you will try to treat "aaa" or "bbb" as a URL, and of course it will not be displayed because it does not have a permalink or substance (if there is an entity, it will display it).

It seems that it is better not to use PATH_INFO in WordPress, but if you have to, you can create a program that accepts PATH_INFO regardless of WordPress, and then pass the parameters to WordPress in some way.

The way to receive it is as above, so the rest is how to pass it, but the easiest way is to redirect it with GET.

$url = "Destination URL?param0=" . $param0 . "&param1=" . $param1;
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $url );

If you want to see parameters in the URL in GET, you can also use a session.

session_start();

$_SESSION[ 'param0' ] = $param0;
$_SESSION[ 'param1' ] = $param1;

$url = "Migrate to URL;
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $url );

If you can use cookies, this is fine, but if you can't,

header("Location: " . $url . "?" . session_name() . "=" . session_id() );

You can pass the session ID in GET.

Related Articles