投稿日:2006年7月25日 レベル:中級者 ソフトウェア:PHP Editors
これから説明するチュートリアルではサイト内での登録/ ログインを行うスクリプトをどのように作成するかについて説明します。ここでPHP、MySQLがインストールされている環境下を想定し、 6つのファイルを操作します。
単純に全ファイルを任意のフォルダに展開し、connect.phpを開き、接続変数を設定します。 次にinstall.phpを動作させ、インストール作業が終了したことを告げるメッセージが表示されたことを確認したら、install.phpを削除します。
全ファイルはここからダウンロードできます。インストール: install.php
require_once("connect.php");
$query = mysql_query("
CREATE TABLE 'members' (
'id' MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT ,
'username' VARCHAR( 50 ) NOT NULL ,
'firstname' VARCHAR( 50 ) NOT NULL ,
'lastname' VARCHAR( 50 ) NOT NULL ,
'password' VARCHAR( 50 ) NOT NULL ,
'date' VARCHAR( 50 ) NOT NULL ,
'ip' VARCHAR( 50 ) NOT NULL ,
PRIMARY KEY ( 'id' ) ,
UNIQUE (
'username'
)
)");
echo "Installed! Please delete this file.";
?>
接続: connect.php
// MySQL connect information.
$c_username = "database_username";
$c_password = "database_password";
$c_host = "localhost";
$c_database = "database_name";
// Connect.
$connection = mysql_connect($c_host, $c_username, $c_password)
or die ("It seems this site's database isn't responding.");
mysql_select_db($c_database)
or die ("It seems this site's database isn't responding.");
?>
登録: register.php
// Check if he wants to register:
if (!empty($_POST[username]))
undefined
?>
<html>
<head>
<title>Register</title>
</head>
<body>
<form action="register.php" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%">Registration</td>
</tr>
<tr>
<td width="100%"><label>Desired Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>First Name: <input type="text" name="firstname" size="25" value="<? echo $_POST[firstname]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Last Name: <input type="text" name="lastname" size="25" value="<? echo $_POST[lastname]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name="password" size="25" value="<? echo $_POST[password]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Verify Password: <input type="password" name="password2" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Register!"></td>
</tr>
</table>
</form>
</body>
</html>
ログイン: login.php
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%">Login</td>
</tr>
<tr>
<td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Login!"></td>
</tr>
</table>
</form>
</body>
</html>
ログアウト: logout.php
特定のメンバーのみに利用を限定したい場合、以下のスクリプトを利用してください。メンバー認証: members.php
// Check his status.
if (!empty($_SESSION[username])) // he got it.
undefined
else // bad info.
undefined
?>
引用:Web Design Library著者:SweDesignz.com翻訳:atuk
スポンサードリンク第2位:Photoshopで洗練したデザインを加える5つの小技 ![]()
第3位:Photoshopで写真に幻想的な霧のかかった効果をつける方法 ![]()
このエントリーのトラックバックURL: