- 论坛徽章:
- 0
|
请高手帮忙指点改正一下以下代码的错误之处
Windows XP SP2 + Apache 1.3.33 + MySQL 4.0.21 + PHP 4.3.10
authnum.php- <?
- Header("Content-type:image/png");
- session_start();
- $authnum_session = '';
- $str = 'abcdefghijkmnpqrstuvwxyz1234567890';
- $l = strlen($str);
- for($i=1;$i<=4;$i++)
- {
- $num=rand(0,$l-1);
- $authnum_session.= $str[$num];
- }
- $_SESSION['authnum_session'] = $authnum_session;
- srand((double)microtime()*1000000);
- $im = imagecreate(50,20);
- $black = ImageColorAllocate($im, 0,0,0);
- $white = ImageColorAllocate($im, 255,255,255);
- $gray = ImageColorAllocate($im, 200,200,200);
- imagefill($im,68,30,$gray);
- $li = ImageColorAllocate($im, 220,220,220);
- for($i=0;$i<3;$i++)
- {
- imageline($im,rand(0,30),rand(0,21),rand(20,40),rand(0,21),$li);
- }
- imagestring($im, 5, 8, 2, $authnum_session, $white);
- for($i=0;$i<90;$i++)
- {
- imagesetpixel($im, rand()%70 , rand()%30 , $gray);
- }
- ImagePNG($im);
- ImageDestroy($im);
- ?>
复制代码
login.php
- <?php
- /*
- --------------------------------------------------------
- CREATE TABLE user (
- id smallint(6) NOT NULL auto_increment,
- user varchar(12) NOT NULL,
- passwd varchar(32) NOT NULL,
- UNIQUE id (id)
- );
- --------------------------------------------------------
- */
- session_start();
- if ($_POST['user']=="" && $_POST['pass']=="" && !isset($HTTP_POST_VARS['authinput']))
- {
- ?>
- <form action="<?php echo $PHP_SELF ?>" method="post">
- user:<input type="text" name="user" value="abcd"><br>
- pass:<input type="text" name="pass" value="1234"><br>
- auth:<input type="text" name="authinput">
- <input type="text" name="authnum" style="width: 80px" value="<? echo $_SESSION['authnum_session']; ?>" />
- <img src="authnum.php?authnum=<? echo $_SESSION['authnum_session']; ?>">
- <input type="submit" value="ok">
- </form>
- <?
- }
- else
- {
- $myconn=mysql_connect("localhost","root","abcd1234");
- mysql_select_db("mydb",$myconn);
- $strSql="select * from user where user='".$_POST['user']."' and passwd='".md5($_POST['pass'])."'";
- $result=mysql_query($strSql,$myconn);
- $row = mysql_fetch_array($result);
- $id = $row[id];
- mysql_close($myconn);
- if($id="" || strcmp($HTTP_POST_VARS['authnum'],$HTTP_POST_VARS['authinput'])!==0)
- {
- echo "Login Fail!";
- }
- else
- {
- echo "OK!<br><a href=\"next.php\">next page</a><br>";
- }
- }
- ?>
复制代码 |
|