Yes, it must be stored in the database. You should use something like wamp, lamp or xampp. These are local servers and give you the mysql database (phpmyadmin) to work with.
to connect to the database, you can use this:
<?php define("DB_HOST", "localhost"); define("DB_USERNAME", "username"); define("DB_PASSWORD", "pass123"); define("DB_NAME", "mydatabase"); try { $db_conn = new PDO('pgsql:host='.DB_HOST.';dbname='.DB_NAME,DB_USERNAME,DB_PASSWORD); } catch(PDOException $e) { print "Error!:".$e->getMessage()."\n"; die(); } ?>
then you can try to create a new table in mysql as follows:
CREATE TABLE subcribe ( subscribeId INT, emailadress VARCHAR(60), .... );
then you can add a subscriber to your database as follows:
If it logs in, you will set a cookie for emailadress:
setcookie('emailadress',$hisEmailadress,time()+3600);
then add the subscriber:
$emailadress=$_COOKIE['emailadress']; $subscriberId = $db_conn->prepare('SELECT MAX(subscriberId) FROM subcribe'); $subscriberId ->execute(); $row = $subscriberId ->fetch(PDO::FETCH_BOTH); $subscriberId = $row[0]+1; $subscriber = $db_conn->prepare("INSERT INTO subscribe(subscriberId, emailadress) VALUES('$subscriberId','$emailadress')"); $subscriber ->execute();
To unsubscribe, simply do the following:
$unsubscribe = $db_conn->prepare('DELETE FROM subscribe WHERE emailadress=:emailadress'); $unsubscribe->bindParam(':emailadress',$_COOKIE['emailadress'],PDO::PARAM_STR); $unsubscribe->execute();
PLEASE LINK, you can do it like this and send it to email recipients:
$length = rand(5, 10); $link= ""; for($i=0;$i< $length;$i++)/*create random link*/ { $char = rand(0, 256); if(($char>=65 && $char<=90) || ($char>=97 && $char<=122) || ($char>=48 && $char<=57)) { $char = chr($char); $link.= $link; } else $i--; } $hash = hash("ripemd160",$link); setcookie('unsubscribe',$hash,time()+300); $result = mail($emailadress, 'unsubscribe link', 'you are about to unsubscribe yourself. Click this link to unsubscribe: http://yourSite.php?link='.$link);
And on this page, you can use the code to remove the subscriber, as described above.
PS: the link itself should not be added to the database, because you can set a cookie valid for a certain time (here it is 5 minutes). on the page of this page you can add an if-test to find out if a cookie is set, and then delete the subscriber. if(isset($_COOKIE['unsubscribe'])){...}
Hope this helps;)