1
登録ページで生成されたユーザー名とパスワードのハッシュを使用してログインページにデータを投稿しようとしています。私はこれが働いていたが、私の人生はそれがなぜ止まったのか分からない。PHPフォワーディングは、登録後にログインページにデータを投稿します。
基本的に、コードは、登録が成功した場合に自動的にログインするようにユーザーをリダイレクトします。ただし、このコードは管理パネルでも使用されるため、ユーザーを追加してユーザー管理画面に戻すことができます。
if (isset($_GET['redirect'])){
if (isset($_GET['login'])){
if($_GET['login'] == "true"){
// So we can log users automatically after registering
$post = http_build_query(
array(
"username" => $username,
"password" => $password
)
);
$context = stream_context_create(
array(
"http"=>array(
"method" => "POST",
"header" => "Content-Type: application/x-www-form-urlencoded\r\n",
"content" => $post
)
)
);
// testing shows that the code gets this far...
// but does not send the following... instead it skips this
$page = file_get_contents('http://example.com/login.php?redirect='.$_GET['redirect'], false, $context);
}
}
header('Location: ' . $_GET['redirect']);
echo('<p><a href="'.$_GET['redirect'] . '">Back to where you were...</a></p>');
}
ハッシュの代わりにパスワードを使用していただきありがとうございます。それは私のログインスクリプトがハッシュではなくパスワードを取る絶対的な権利です。 ただし、file_get_contentsはまだスキップされています。 登録ページ内でユーザーをログインさせることができるかどうか試してみるつもりです。うまくいけばうまくいきます。 – Panda
私は、ログインページにデータを送信するのではなく、ユーザーセッションを作成しました。ありがとうございました。 – Panda