LoginSignup
0
0

Wordpress にユーザ名・パスワードなしでダブルクリックだけでログインする

Last updated at Posted at 2023-09-19

WP本体をいぢる必要はなく、 生PHP (?) , 生Javascript (?) だけで書いた以下のPHPをWP直下におくだけです。
(Wordpress6.0で動作確認)

以下のPHPファイル(xxx.php)を、WP直下におきます。

https:// site //xxx.php?yyyyyy=zzzzzzz のショートカットリンク を作っておけば、すぐにログインできます。

セキュリティ上の問題はありますが、 xxx, yyy, zzz を超長く、複雑にしておけば、多少はマシかと。
自己責任でお願いします。

メリットは不要になったら、このPHPファイルを削除するだけでよく、WP本体ファイルには手を入れないでよいということです。

<?php 

//このページを wordpress 直下に配置する。 この pageネームを "任意ログイン.php" とすると,  「https://www.任意のドメイン/任意ログイン.php?任意のGET変数=任意の値」で アクセスできる。
//その GET変数を含むショートカットを作っておけば、打ち込むことなくすぐにアクセスできる。クッキーが切れていても勿論。
//ただし極端に通信速度が遅い場合はアクセスできない場合があるが、更新ボタンを押して読み直せばだいたいイケる。

//セキュリティ上どうかと思うが, このページ名, GET変数名, GET変数値を複雑にしておけば, そうそうアクセスできないのではないか。


$login = <<< HTML

<html>
<body>

<script>

var flag=0;


const mainWindow= window.onload = function() {

document.loginform.target = "targetFrame";
document.loginform.method = "post";
document.loginform.submit();

document.getElementById('targetFrame').onload = function() {

if(flag==0){
document.loginform.submit();
flag=1;
}


};
          

};

</script>

<style>

#wrap_mienai { display:none;}

</style>

<div id="wrap_mienai">
<form name="loginform" id="loginform" action="https://www.xxxxxxxxxxxxxx.jp/wp-login.php" method="post">
<p>
<label for="user_login">ユーザー名またはメールアドレス</label>
<input type="text" name="log" id="user_login" class="input" value="ログインID" size="20" autocapitalize="off" autocomplete="username" required="required" />
</p>

<div class="user-pass-wrap">
<label for="user_pass">パスワード</label>
<div class="wp-pwd">
<input type="password" name="pwd" id="user_pass" class="input password-input" value="ログインパスワード" size="20" autocomplete="current-password" spellcheck="false" required="required" />
<button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="パスワードを表示">
<span class="dashicons dashicons-visibility" aria-hidden="true"></span>
</button>
</div>
</div>
<p class="forgetmenot"><input name="rememberme" type="checkbox" id="rememberme" value="forever"  /> <label for="rememberme">ログイン状態を保存する</label></p>
<p class="submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="ログイン" />
<input type="hidden" name="redirect_to" value="https://www.xxxxxxxxxxxxxx.jp/wp-admin/" />
<input type="hidden" name="testcookie" value="1" />
</p>
</form>

</div>


<iframe name="targetFrame" id="targetFrame" width="100%" height="100%" >
</iframe>

</body>
</html>

HTML;


if(isset($_GET["任意のGET変数"])){
if($_GET["任意のGET変数"]=="任意の値"){echo $login;}
}



?>

コード中にフォームがありますが、フォーム関係は Wordpress のログインページを抜粋したものです。
つまり、WPのログインページにユーザ・パスワードを渡しているだけです。

なおクッキーとかセッションとは全く関係ありません。なくてもログインできます。

動作確認はしてます。

フォームのコードはありますが、開いたらすぐに管理画面にジャンプするという動作です。

0
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
0
0