如何检查文件中的行 (php)
How to check line in file (php)
我是 php 的新手,想制作一个简单的 php 脚本来检查我的 html 网站的表单。
回答问题:
我有一个文件,它是用户名,我想检查其中的密码(第 1 行)是否与我网站上 "password" 字段中的密码相同。当它像这样时,它应该打开一个站点。
也许检查文件是否存在会很好 :D
这是我的 php 文件,它的名字是 "check.php":
<?php
$f = fopen($_POST["name"], "r");
$theData = fgets($f);
if ($_POST["pw"] == $theData) {
$ch = curl_init("site.com");
curl_exec($ch);
}
fclose($f);
?>
这是我的 html-文件:
<h2>Check</h2>
<form action="check.php" method='post'>
<b>Name: </b><input name="name" type="text" value="Name"> <br>
<b>Password: </b><input name="pw" type="text" value="Passwort"> <br>
<input type="submit" value="Check">
<input type="reset" value="Reset">
</form>
希望有人能帮帮我^^
我现在已经尝试了很多东西,但没有任何效果。
要处理表单字段,您应该在 check.php 文件中这样做(最简单的一个)
if(isset($_POST['submit']))
{
$name = $_PSOT['name'];
$password = $_POST['password'];
if($name == 'admin' && $password == 'admin')
{
header('Location:admin.php');exit;
}else{
echo 'Wrong user name or password';
}
}
may be you are asking to do like this
if(isset($_POST['submit']))
{
$name = $_PSOT['name'];
$password = $_POST['password'];
$file_type = '.txt';
$path = 'path to folder/'.$name.$file_type;
if(file_exists($path))
{
$user_pass = fopen($path, "r");
$flag = 0;
while(!feof($user_pass))
{
$p = fgets($user_pass);
if($password == $p)
{
$flag = 1;
}
}
fclose($user_pass);
if($flag == 1)
{
header('Location:to your page link/weblink');exit;
}else{
echo 'Wrong password';
}
}else{
echo 'User does not exists';
}
}
我是 php 的新手,想制作一个简单的 php 脚本来检查我的 html 网站的表单。
回答问题: 我有一个文件,它是用户名,我想检查其中的密码(第 1 行)是否与我网站上 "password" 字段中的密码相同。当它像这样时,它应该打开一个站点。
也许检查文件是否存在会很好 :D
这是我的 php 文件,它的名字是 "check.php":
<?php
$f = fopen($_POST["name"], "r");
$theData = fgets($f);
if ($_POST["pw"] == $theData) {
$ch = curl_init("site.com");
curl_exec($ch);
}
fclose($f);
?>
这是我的 html-文件:
<h2>Check</h2>
<form action="check.php" method='post'>
<b>Name: </b><input name="name" type="text" value="Name"> <br>
<b>Password: </b><input name="pw" type="text" value="Passwort"> <br>
<input type="submit" value="Check">
<input type="reset" value="Reset">
</form>
希望有人能帮帮我^^ 我现在已经尝试了很多东西,但没有任何效果。
要处理表单字段,您应该在 check.php 文件中这样做(最简单的一个)
if(isset($_POST['submit']))
{
$name = $_PSOT['name'];
$password = $_POST['password'];
if($name == 'admin' && $password == 'admin')
{
header('Location:admin.php');exit;
}else{
echo 'Wrong user name or password';
}
}
may be you are asking to do like this
if(isset($_POST['submit']))
{
$name = $_PSOT['name'];
$password = $_POST['password'];
$file_type = '.txt';
$path = 'path to folder/'.$name.$file_type;
if(file_exists($path))
{
$user_pass = fopen($path, "r");
$flag = 0;
while(!feof($user_pass))
{
$p = fgets($user_pass);
if($password == $p)
{
$flag = 1;
}
}
fclose($user_pass);
if($flag == 1)
{
header('Location:to your page link/weblink');exit;
}else{
echo 'Wrong password';
}
}else{
echo 'User does not exists';
}
}