PHP kimlik doğrulama?

5 Cevap php

I need to make an authentication script in php. I have already made a login.php page, where the user can enter his unsername/password and it gets checked against a database. If the unsername/password are correct, the user should be forwarded to members.php page together with a $_SERVER['username'] variable.

What is the command in PHP to go to another webpage, in this case members.php ?

pseudocode ben böyle görüyorum:

if ( unsername/password are OK ) { $_SERVER['username'] = $username; goto(members.php); }

Teşekkürler!

5 Cevap

Sen bir şey $ _SERVER ayarlanamaz. Bunun yerine bir oturumu + kurabiye kullanmalısınız. Sonra istemci Yer başlığını kullanarak members.php gitmek için biliyorum sağlayabilirsiniz:

session_start();
$_SESSION['username'] = $username;
header("Location: members.php");
exit(0);
header('Location: members.php');

Herhangi bir çıktı gönderilmeden önce başlıklar gönderilmesi gerektiğini unutmayın.

(Henüz kendi tarayıcısı için herhangi bir çıktı gönderdi değil sağlanan) PHP ile bir kullanıcıyı yönlendirmek için kod header( 'Location: members.php' );.

Bir kenara, muhtemelen $_SERVER[] yerine $_SESSION[] kullanmak isteyen

Kesinlikle bu durumda oturumları kullanmalısınız.

İşte bir örnek:

session_start();
$_SESSION[ 'username' ] = $_POST[ 'username' ];
header( 'Location: members.php' );

exit();

@ Nuqqsa başlıkları çıktı tamponlama kullanmak eğer vücut içerik gönderilen sonra bile gönderilebilir. Bunu yapabilirsiniz output_buffering ayarlayarak php.ini = Açık veya zamanında çıktı tamponlama işlevlerini çağırarak