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:

<?IF($USER_ID$)?>
    <div align="center">
        <p>
            <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>
        </p>
    </div>
    <hr>
    <?$PHPCODE$("http://phpexample.ucoz.com/php/example000/example000.php?uid=",$USER_ID$)?>
<?ELSE?>
    <div id="phpdiv">
        <p>Guests are prohibited from viewing this page. Please, authorize yourself.</p>
    </div>
<?ENDIF?>


PHP-script of this example:

<?php
    session_start();
    if(count($_POST)>0){
        $___notjson=1;
        if(isset($_SESSION['captcha_keystring']) && $_SESSION['captcha_keystring'] == $_POST['keystring']){
            $lines = file('subscr.dat');
            if ($_POST['atype'])
            {
                $status_ok=0;
                foreach ($lines as $line_num => $line) {
                    if (trim($line)==$_POST['userid'])
                    {
                        unset($lines[$line_num]);
                        file_put_contents('subscr.dat', $lines);
                        $status_ok=1;
                        break;
                    }
                }
                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')";
            }
            else
            {
                $status_err=0;
                foreach ($lines as $line_num => $line) {
                    if (trim($line)==$_POST['userid'])
                    {
                        $status_err=1;
                        break;
                    }
                }
                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')";
                }
            }
        }else{
            echo "$('#captcha_result').html('Incorrect security code')";
        }
        exit;
    }
    unset($_SESSION['captcha_keystring']);
?>

<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>
</form>
<div id='captcha_result'></div>


PHP Captcha Script: http://www.captcha.ru/
Date 18.02.2011
Comments:
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
sevsv
Michaelkr 01.06.2014 18:58
123
StephenBoxy 31.03.2014 08:43
123
579243 google 11.12.2013 04:57
http://www.google.com/
777979 google 10.12.2013 00:55
http://www.google.com/
Сеть ошибка подключения 17.10.2013 21:51
http://oshibka.elektrosha.ru/?p=553 Miranda ошибка подключения к серверу
finishingtouchesinteriors 228 07.09.2013 23:50
hello word!
finishingtouchesinteriors.com 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 ]