SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    austalia
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie check appears to disable script

    Thanks to some advice on this forum I managed to get my page correctly checking for a cookie and processing the page as intended. Unfortunately a form to email script actioned when the form is submitted doesnít work now. (it should send the value of 'email' to a specified address). The script hasnít been modified, just the PHP code that determines whether to display the login form or not.

    I have included the amended logic below. Appreciate suggestions for what is the problem here.

    Thanks
    David


    <h1>Free resources</h1>
    <?
    if (isset($_COOKIE['email'])) {
    ?>
    <ul><li><a href="#">Access free resources</a></li></ul>
    <?
    } elseif ($_GET['checkit']) {
    echo "<ul><li><a href="#">Access free resources</a></li></ul>";
    }
    else {
    ?>
    <p>Please enter your email address below to access the free SMILE resources.</p>
    <form name="emailaddress" id="emailaddress" title="Email address" onsubmit="return formvalidation();" method="post" action="<? echo $_SERVER['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">
    <!--
    document.getElementById('email').focus();
    // -->
    </script>

  2. #2
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ehmer
    <form name="emailaddress" id="emailaddress" title="Email address" onsubmit="return formvalidation();" method="post" action="<? echo $_SERVER['cgi-bin/formtomailscript2.cgi']; ?>">
    That line looks odd, shouldn't it be:

    <form name="emailaddress" id="emailaddress" title="Email address" onsubmit="return formvalidation();" method="post" action="cgi-bin/formtomailscript2.cgi">

    Douglas
    Hello World

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Australia
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or action="/cgi-bin/formtomailscript2.cgi" if you have subdirectories and you are calling from a page in one of these subdirectories.

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    austalia
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Still no success

    the path is ok without the leading slash. If I remove:

    <? echo $_SERVER['cgi-bin/formtomailscript2.cgi']; ?>

    and replace it with:

    "cgi-bin/formtomailscript2.cgi"

    then the script executes and sends of the email to the specified account, but doesn't recognise the cookie, so the form is displayed each time the page loads.

    However is I use the $_SERVER approach the cookie aspect works fine but the form to email script doesn't execute.

    Any further ideas?

  5. #5
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ehmer
    if I use the $_SERVER approach the cookie aspect works fine but the form to email script doesn't execute.

    Any further ideas?
    Have a look at the HTML source code in your browser. I'm betting that when you "use the $_SERVER approach" you end up with action="" in your HTML page. It won't execute the script becuse you're not telling it where the script is!

    Douglas
    Hello World

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    austalia
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may be correct Douglas and I'll check it out. In the meantime if it isn't correct, what should the value of action be?

    David

  7. #7
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should be an absolute or relative path to the script on the server you want to execute.

    If the script you want to execute is at cgi-bin/formtomailscript2.cgi then the action should look like this:

    action="/cgi-bin/formtomailscript2.cgi"

    If you just have action="", then the browser will use the current URL as the action URL.

    Douglas
    Hello World

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2003
    Location
    austalia
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it will execute the script with the action that way, but fails to recognise the cookie and related logic. ie won't display the link if a cookie is present on the users computer, still shows the form.


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
  •