1.包围$pswd1和$pswd2的单引号不可删除,否则无法向mysql中插入数据。
<?php
$con=mysql_connect("localhost","root","00001111");
if(!$con){
die("Could not connect MySQL database!");
}
mysql_select_db("sql_test",$con);
$pswd1=md5("0000");
$pswd2=md5("1111");
$sql="INSERT INTO logins (username,pswd)
VALUES
('John','$pswd1'),
('Sam','$pswd2')";
mysql_query($sql,$con);
mysql_close($con);
?>2.Linux:文件中的换行符为“\n”;Windows:文件中的换行符为“\r\n”;
示例:基于文件的身份验证
文件authenticationFile.txt的内容如下:
jack:ae2bac2e4b4da805d01b2952d7e35ba4
milk:ae2bac2e4b4da805d01b2952d7e35ba4
立即学习“PHP免费学习笔记(深入)”;
<?php
$authorized=false;
if(isset($_SERVER['PHP_AUTH_USER'])&&isset($_SERVER['PHP_AUTH_PW'])){
$authFile=file("authenticationFile.txt");
if(in_array($_SERVER['PHP_AUTH_USER'].":"
.md5($_SERVER['PHP_AUTH_PW'])."\n",$authFile)){
$authorized=true;
}
}
if(!$authorized){
header('WWW-Authenticate:Basic Realm="Secret Stash"');
header('HTTP/1.0 401 Unauthorized');
print('You must provide the proper credentials');
exit;
}
?>以上就介绍了PHP 错误问题集合,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号