Free resources!

You will need to enter your address each time you visit the free resources page as your browser does not support cookies.

"; } else { ?>

Please enter your email address below. (Privacy policy)

Free resources

To access additional information and downloadable resources that will assist with your implemenation of SMILE we ask that you supply your email address.

[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <42e60480$0$5455$5a62ac22@per-qv1-newsreader-01.iinet.net.au> [ref] => [htmlstate] => on_nl2br [postusername] => David [ip] => ehmer@iinet.net [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 1 [islastshown] => [isfirstshown] => 1 [attachments] => [allattachments] => ) --> cookie checking problem - PHP Development
Professional Web Applications Themes

cookie checking problem - PHP Development

Hi I have a page (page 1) which checks for the existence of a cookie. If present a link is displayed, if not a form input box is displayed. Upon entering an email address into the input box, access is granted to a subsequent page (page 2). The action attribute of the form looks like this: action="cgi-bin/formtomailscript2.cgi" This executes the script fine when the form is submitted but the page doesn't check for the cookie on later visits (ie it displays the input box again rather than the link) If the action attribute is changed to look like this: <? ...

  1. #1

    Default cookie checking problem

    Hi

    I have a page (page 1) which checks for the existence of a cookie. If
    present a link is displayed, if not a form input box is displayed. Upon
    entering an email address into the input box, access is granted to a
    subsequent page (page 2). The action attribute of the form looks like this:

    action="cgi-bin/formtomailscript2.cgi"

    This executes the script fine when the form is submitted but the page
    doesn't check for the cookie on later visits (ie it displays the input box
    again rather than the link)
    If the action attribute is changed to look like this:

    <? echo
    $_SERVER['http://www.smilelearning.com.au/cgi-bin/formtomailscript2.cgi'];
    ?>

    Then the script is not executed, but the page successfully checks for the
    cookie and displays the link on later visits, rather than the input box.
    Appreciate an explanation about what's happening here and how to make sure
    the script is executed and the cookie is checked.

    This one really has me stumped. (Full page code below)

    Thanks
    David
    _________________________________

    <?php
    if (preg_match("/\w+/", $_POST['email']) )
    {
    setcookie("email", $email, time()+365 * 86400);
    header("Location: $_SERVER[SCRIPT_NAME]?checkit=1");
    exit;
    }
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>SMILE Learning: Free resources</title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function formvalidation() {
    var message = "";
    if
    (!/^\w+([\.-]?\w+)*\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(doent.emailaddress
    ..email.value)){
    message = message + "\n Please enter a valid e-mail address";
    }
    if ( message.length > 0 ) {
    alert( message );
    return false;
    }
    else {return true;}
    }
    // -->
    </script>
    <meta http-equiv="Content-Type" content="text/html; cht=iso-8859-1" />
    </head>
    <body id="resources">
    <div id="center_container">
    <?php include("includes/nav_main.php"); ?>
    <div id="columns">
    <div id="leftcolumn">
    <h1>Free resources!</h1>
    <?
    if (isset($_COOKIE['email'])) {
    ?>
    <ul>
    <li><a href='freeresourceslinks.php'>Access Free Resources</a></li>
    </ul>
    <?
    } elseif ($_GET['checkit']) {
    echo "
    <p>You will need to enter your address each time you visit the free
    resources page as your browser does not support cookies.</p>
    <ul>
    <li><a href='freeresourceslinks.php'>Access Free Resources</a></li>
    </ul>
    ";
    }
    else {
    ?>
    <p>Please enter your email address below. <a
    href="privacy.php">(Privacy policy)</a></p>
    <form name="emailaddress" id="emailaddress" title="Email address"
    onsubmit="return formvalidation();" method="post"
    action="cgi-bin/formtomailscript2.cgi">
    <table id="emailtable">
    <tr>
    <td class="input"><input name="email" id="email" type="text"
    size="23" /></td>
    </tr>
    <tr>
    <td>
    <div align="center">
    <input name="submit" id="submit" type="submit" value="submit" />
    </div>
    </td>
    </tr>
    </table>
    </form>
    <script language="JavaScript" type="text/javascript">
    <!--
    doent.getElementById('email').focus();
    // -->
    </script>
    <? } ?>
    </div>
    <div id="rightcolumn">
    <div id="content">
    <h1>Free resources</h1>
    <p>To access additional information and downloadable resources that
    will assist with your implemenation of SMILE we ask that you supply your
    email address.
    </div>
    </div>
    </div>
    <?php include("includes/footer.php"); ?>
    </div>
    </body>
    </html>


    David Guest

  2. #2

    Default Re: cookie checking problem

     

    Probably your page is getting cached somewhere along way. Add headers
    to prevent caching, or add a random string ( eg
    ....formtomailscript2.cgi&r=1qa7h ) to the end of the URL to ensure that
    it is refetched.
     

    There will be no such environment variable so this will resolve to
    action="" which in some browsers is treated as the name of the current
    page.

    ---
    Steve

    Steve Guest

  3. #3

    Default Re: cookie checking problem


    Further to this, in your first section of code which checks if there's
    anything in the FORM 'email' field:

    <?php
    if (preg_match("/\w+/", $_POST['email']) )
    {
    setcookie("email", $email, time()+365 * 86400);
    header("Location: $_SERVER[SCRIPT_NAME]?checkit=1");
    exit;
    }
    ?>

    Where does $email get set? If it has no value, then the setcookie()
    function generates a cookie removal header. This is probably not what
    you intended. Try this:

    setcookie("email", $_POST['email'], time()+365 * 86400);


    ---
    Steve

    Steve Guest

Similar Threads

  1. problem with cookie
    By stephan beal in forum PHP Development
    Replies: 3
    Last Post: April 2nd, 01:15 PM
  2. checking login cookie
    By CF Nut in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: March 29th, 04:08 PM
  3. Cookie Problem -Please Help
    By CF_N_Montreal in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: March 16th, 05:51 PM
  4. cookie's problem
    By Carnacky in forum ASP.NET Security
    Replies: 0
    Last Post: May 20th, 01:34 PM
  5. Checking if a cookie has already been set
    By Andrew Duffy in forum ASP
    Replies: 2
    Last Post: October 10th, 03:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139