david212 Posted July 21, 2010 Share Posted July 21, 2010 My hometask says: each user must register own email address to download the file. You must use cookies to detect whether the user has already registered, and to ensure that the user downloads the file only once within 7 days of registering. I have been making a lot of things but i can get it working. Please help! The last code i wrote is this: <?php if (!empty($_POST['delete_cookie'])) { setcookie("sevendays", "", time()-3600); } if(isset($_POST['terms'])AND(isset($_POST['email']))AND(empty($_COOKIE["sevendays"]))){ $email = $_POST['email']; setcookie("sevendays", "email", time()+60*60*24*7); $filepath = $_SERVER['DOCUMENT_ROOT']."/.php_files/acme_brochure.pdf"; if (file_exists($filepath)) { header("Content-Type: application/force-download"); header("Content-Disposition:filename=\"brochure.pdf\""); $fd = fopen($filepath,'rb'); fpassthru($fd); fclose($fd); } } ?> <?php if (isset($_POST['ok'])){ if($_POST['mail']== $_COOKIE['email']){ echo "This email address has already been registered<br>"; }else { echo "<h3>Thank you!</h3>"; } } ?> <?php if (!empty($_COOKIE["sevendays"])) echo "only in 7".$_COOKIE["sevendays"]." days!"; if ($_COOKIE["sevendays"]) { echo $_COOKIE["sevendays"]; ?> <a href="download.php?delete_cookie=1">Not my email: <? echo $_COOKIE["sevendays"]; ?>?</a> <?php }else { ?> <h3>Please register</h3> <form method="POST" action="?"> <table> <tr> <td align="right"> Name: </td> <td align="left"> <? if ($_COOKIE['name']) { echo $_COOKIE['name']; } else { ?> <input type="text" size="25" name="name" value="<? echo $_POST['name']; ?>"> <?php } ?> </td> </tr> <tr> <td align="right"> Email: </td><td align="left"> <? if ($_COOKIE['email']) { echo $_COOKIE['email']; } else { ?> <input type="text" size="25" name="email" value="<? echo $_POST['email']; ?>"> <?php } ?> </td> </tr> <tr> <td colspan="2"> <input type="checkbox" name="terms" checked="checked">I accept terms and conditions.<br/> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="ok" value="SUBMIT" /> </td></tr> </table> </form> <?php } ?> i can't get it working. Please help! Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted July 21, 2010 Share Posted July 21, 2010 . Quote Link to comment Share on other sites More sharing options...
david212 Posted July 21, 2010 Author Share Posted July 21, 2010 nice answer but i really need the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.