Script author: jon
Subscription for a mailing list
     It is shown in this example how to create a verification code and subscribe/unsubscribe user for any kind of a mailing list. It is meant that the dispatch itself is carried out by means of a server script or a program. Script creates a form with the relevant fields and the verification code on the page. User selects the action he wants to do (subscribe/unsubscribe) and enters the code from the image. If the entered code matches with the imaged one, the form is sent and the actions are carried out. This script may be used almost everywhere, where the security code is used to confirm user's actions. (e.g. enabling and disabling some user options, features etc) The source code of this example is shown below.

In the template of the page:

    <div align="center">
            <b>This example shows the way of using the script to subscribe /unsubscribe for any kind of mailing lists for the current user, using security code</b>
    <div id="phpdiv">
        <p>Guests are prohibited from viewing this page. Please, authorize yourself.</p>

PHP-script of this example:

        if(isset($_SESSION['captcha_keystring']) && $_SESSION['captcha_keystring'] == $_POST['keystring']){
            $lines = file('subscr.dat');
            if ($_POST['atype'])
                foreach ($lines as $line_num => $line) {
                    if (trim($line)==$_POST['userid'])
                        file_put_contents('subscr.dat', $lines);
                if ($status_ok) echo "$('#captcha_result').html(You have unsubscribed from the mailing list')";
                else echo "$('#captcha_result').html('You haven't been subscribed to the mailing list')";
                foreach ($lines as $line_num => $line) {
                    if (trim($line)==$_POST['userid'])
                if ($status_err) echo "$('#captcha_result').html('You have been subscribed to the mailing list')";
                else {
                    if (file_put_contents('subscr.dat', $_POST['userid']."\n", FILE_APPEND)==FALSE) echo "$('#captcha_result').html('Error, try again later')";
                    echo "$('#captcha_result').html('You have subscribed to the mailing list')";
            echo "$('#captcha_result').html('Incorrect security code')";

<p>News letter</p>
<form action="/php/example000/example000.php" method="post" onsubmit="_uPostForm(this,{dataType:'script'});return false;" onerror="alert('Error');">
<p><input type="hidden" name="userid" value="<?echo $_GET['uid']?>"></p>
<p><input type="radio" name="atype" value="0" CHECKED/>Subscribe</p>
<p><input type="radio" name="atype" value="1" />Unsubscribe</p>
<p><img src="/php/example000/index.php?<?php echo session_name()?>=<?php echo session_id()?>"></p>
<p><input type="text" name="keystring"></p>
<p><input type="submit" value="Ok"></p>
<div id='captcha_result'></div>

PHP Captcha Script:
Date 18.02.2011
1 2 3 ... 6 7 »
Larry L Lester 15.01.2015 14:22
Please take me off any and all future mailing lists, for Iam not interested,Thank You.
AyaQPaiva 12.01.2015 09:47
Michaelkr 01.06.2014 18:58
StephenBoxy 31.03.2014 08:43
579243 google 11.12.2013 04:57
777979 google 10.12.2013 00:55
Сеть ошибка подключения 17.10.2013 21:51 Miranda ошибка подключения к серверу
finishingtouchesinteriors 228 07.09.2013 23:50
hello word! 121 06.09.2013 23:52
hello word!
lambtonwildlife 795 04.09.2013 12:23
hello word!
1-10 11-20 21-30 ... 51-60 61-65
Only registered users can add comments.
[ Registration | Login ]