私はphpの初心者です。phpを使用して簡単なログインページを作成し、データベースにないニックネームを入力するとその旨が表示されるようにします。そうでない場合は、パスワードが正しくないことを通知します。学校のサーバーを使用しているため、サーバーに関する特定の質問に答えられない場合があります。最も重要なのは、fopen()を使用する権限がないため、file_put_contentsです。私はそれが機能するようになっていないので、それが機能するかどうかさえわかりません。これまでのところ、login.php、check.php、numberconverter.phpがあります。これらは、数値を文字列に変換するのに役立つ関数です。(この場合、UNIX時間)。私はnumbercoverter.phpがテストから機能することを知っています。
login.php:
<?
define('__ROOT__',dirname(dirname(__FILE__)));
require_once(__ROOT__.'/shopsite/numberconverter.php');
echo "<!--root: ".__ROOT__."/shopsite/ -->\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login to the Shopsite</title>
<script type="text/css">
"error" {
background-color:#FF;
color:#FFFFFF;
}
</script>
<script type="text/javascript">
<?php
$nick="";
$i=false;
if(isset($_GLOBALS['file']))
{
$i=true;
$nick=file_get_contents("file.txt");
$nick=preg_split("^nick:",$nick);
}
else
{
$_GLOBALS['file']='file'.convert(time()).'.txt';
}
?>
functions error(i)
{
if(i)
{
document.getElementById('error').innerHTML="Nick <?php echo $nick; ?> was not found. Try again or <a href=\"register.php\">register</a>";
}
else
{
document.getElementById('error').innerHTML="Password incorrect. Try again or <a href=\"register.php\">register</a>";
}
}
//-->
</script>
</head>
<body <?php if($i) { echo "onload=\"error(".((strlen($nick[0])<0) ? 1 : 0).")\""; }?> >
<p id="error"></p>
<?php
$chk = time();
echo "File name: ".$_GLOBALS['file']."\n";
echo "unix time raw: ".$chk."\n";
echo "unix time converted: ".convert($chk)."\n";
?>
<form id="form" action="check.php" method="post">
<p>username: <input type="text" name="nick" id="nick" /></p>
<p>password: <input type="text" name="pass" id="pass" /></p>
<input type="submit" value="Log in"/>
</form>
</body>
</html>
check.php:
<?php
$c = mysql_pconnect("localhost","hehe","hehe");
mysql_select_db("test",$c);
$r = mysql_query(sprintf("select * from UserTable where (nick=(\"%s\") AND pass=SHA1(\"%s\"))",$_POST['nick'],$_POST['pass']),$c) or die("something wrong with mysql,1");
if(mysql_num_rows($r)==0)
{
$testn = mysql_query(sprintf("select * from UserTable where nick=(\"%s\")",$_POST['nick']),$c) or die("something wrong with mysql,2");
if(mysql_num_rows($testn)==0)
{
//file_put_contents($_GLOBALS['file'],"nick:".$_POST['nick']);//
file_put_contents('test.txt',"nick");
}
else
{
//file_put_contents($_GLOBALS['file'],"pass");
file_put_contents('test.txt',"pass");
}
mysql_close($c);
header("Location:http://cs4.sunyocc.edu/~j.d.dancks/shopsite/login.php");
}
else
{
mysql_close($c);
session_start();
$_SESSION['nick'] = $_POST['nick'];
$_SESSION['email'] = $_POST['email'];
}
?>