LoginSignup
1
0

More than 5 years have passed since last update.

GETをPOSTにしてリダイレクト

Last updated at Posted at 2018-10-12

やりたいこと

GETパラメータをPOSTパラメータに変更してリダイレクトしたい。

実現方法

JavaScriptでsubmitする。
jQueryだけでも実現可能だが取り方が面倒なのでPHPでやる。

ソースコード

get2post.php
<!DOCTYPE html>
<head>
<meta charset='utf-8'>
</head>
<html>
<body onload='document.redirectForm.submit();'>
<form name='redirectForm' method='post' action='<?= htmlspecialchars($_GET["rd_url"]) ?>'>
<input type='hidden' name='param1' value='<?= htmlspecialchars($_GET["param1"]) ?>' />
<input type='hidden' name='param2' value='<?= htmlspecialchars($_GET["param2"]) ?>' />
</form>
</body>
</html>

例えばここにPOSTしたい場合
http://example.com/destination

以下のようにURLエンコードしてrd_urlに渡してやる
http://example.com/get2post.php?rd_url=http%3a%2f%2fexample%2ecom%2fdestination&param1=10&param2=200

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0