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 4 5 »
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
StephenBoxy 31.03.2014 08:43
123
Сеть ошибка подключения 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!
ok 15.08.2013 11:02
ok
24236 31.07.2013 02:21
These days sandals are largely made from brown leather but can also be made from foam and from latexWhen doing a cleanup, make sure that the wheels and rims are cool It features rolled leather handles, wide zip top closure and can be locked using a Louis Vuitton engraved padlock one side It is also best to bring adorable chain watches that you can personalize and even add to your collectibles But wiping out the ecologically-friendly trait, the most possible ending for this bag is accompanying with dusts and cobwebs in the deep corner of show windowGift for her is one theme of Louis Vuitton products
Car Insurance 22.07.2013 18:17
Classic Car Insurance
1-10 11-20 21-30 31-40 41-43
Only registered users can add comments.
[ Registration | Login ]