- session_start: documentation ( source)
- file_put_contents: documentation ( source)
<?php
/**
* Created by PhpStorm.
* User: Tobias Cervin
* Date: 2017-10-02
*/
session_start();
require_once 'Key.php';
if(isset($_POST['email']) && isset($_POST['key'])){
$email = $_POST['email'];
$filename = 'subscriptions.txt';
if (!empty($email)){
if(Key::isValid($_POST['key'])){
//If key is valid it takes email from the form and writes it to the existing or created file 'subscriptions.txt'
file_put_contents($filename, $email + '\n', FILE_APPEND | LOCK_EX);
echo 'You have been added as a subscripteee!';
}
else{
echo 'You little fraud, get out of here!!!';
}
}
else{
echo 'Wrong email input...';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>The Awesome Mail Spamming Subscription!</title>
</head>
<body>
<form action="" method="post">
<div class="subscribe">
<strong>Please Subscribe!</strong>
<div class="field">
eMail: <input type="email" name="email">
</div>
<input type="submit" value="subscribed">
<input type="hidden" name="key" value="<?php echo Key::generate(); ?>">
</div>
</form>
</body>
</html>