Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Clearing history, cookies and cache files from PHP

Posted by paula (paula), 7 September 2005
Hi

I'm attempting a form for sending email, and there's a problem with loading the actual page which seems to be related to caching.

What happens is, when you click the submit button, the form sends the email and returns a message saying "Your message has been sent". If you then try to reload the page, all you get is this message - no form - and the recipient gets an empty email (haven't quite mastered the technical bits required to check if there's a valid email address).

The only way of fixing this is to clear the temporary files, delete the cookies, clear the history, then shut the browser (IE6 in this case) window and open it afresh. The form then loads as it should.

So I'm wondering if there's some variable I could include that tells the browser to clear itself out so the page reloads OK. If anyone can let me know, I'd appreciate it

(Obviously the real solution would be to make the form work properly... and someday it will )

Thanks in advance,
Paula

Posted by admin (Graham Ellis), 7 September 2005
How are you linking the two pages?  Via a cookie, or via a hidden field?

If it's via a cookie, then you should destroy th ecookie when you send the email by sending a new cookie with a negative time to live.   If you're using a hidden field, simply make sure you remove the hidden field from the next form.

It's possible that you're using cookies via sessions ... and if that's the cas you can get rid of the cookie via a session_destroy once the email has been sent.

Caching is - err - a bit of a nuisance at time, especially during testing. But if you make sure you clear it out as described above, you whould be OK.   Otherwise we would have people forever resubmitting the same orders!

Graham

P.S. If the answer here's a bit general, please post up a few of the specific lines of code.   I know it's possibly based on code I wrote but I'm sure you've enhanced it since!

Posted by paula (paula), 8 September 2005
Hi

I'm not actually linking two pages. I started with this script:

<html>
   <head><title>Feedback</title></head>
   <body>

       <?php

       // Handle POST method.
       if ($_POST)
       {
           $name = $_POST['name'];
           $email = $_POST['email'];
           $comments = $_POST['comments'];
                 $sendto = "me@here.ac.uk";

           // Compose simple text message:
           $message = "Message from $name ($email)\n\nComments:\n\n$comments";

           // Send message to me
           $headers  = "MIME-Version: 1.0\r\n";
           $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

           mail($sendto,"Message for Paula sent via the LD and D website",
                        $message,
                        "From: $email\n".
                        "Reply-to: $email"
                        );

           // Thank the generous user
           print "Your message has been sent.\n";
       }
       else
       {

       ?>

       <h1>Feedback</h1>

       <form action="<?= $PHP_SELF ?>" method="post">

           <p>Name: <input type="text" name="name" /></p>

           <p>Email: <input type="text" name="email" /></p>

           <p>Comments:</p>
           <p><textarea name="comments"></textarea></p>

           <p><input type="submit" value="Send!" /></p>

       </form>

       <?php

       }

       ?>

   </body>
</html>


And adapted it, using the notes and examples from your course, into this:

<?php

       if ($_REQUEST)
       {
           $name = $_REQUEST['name'];
           $email = $_REQUEST['email'];
           $idno = $_REQUEST['idno'];
                 $comments = $_REQUEST['comments'];
                 $sendto = "me@here.ac.uk";

           // Compose simple text message:
           $message = "Message from $name (I.D. number: $idno)\n\n\n$comments";

           // Send message to me
           mail($sendto,"Message for Paula sent via the LSS website",
                        $message,
                        "From: $email\n".
                        "Reply-to: $email"
                        );

           // Thank the generous user
           print "Your message has been sent.\n";
       }
       else
       {

       ?>

You may contact Paula Unger by using the form below. Please remember to include your name,
email address and student I.D number. Messages cannot be delivered without these details.
Thank you.
<p />
<form action="<?= $PHP_SELF ?>" method="post">
     <label for="name"><strong>Your name</strong>:</label><br />
           <input type="text"
                    id="name"
                    name="name"
                    value="<?php print(htmlspecialchars($_REQUEST['name'])); ?>" />
                    <br />
     <label for="idno"><strong>Your I.D number</strong>:</label><br />
           <input type="text"
                    id="idno"
                    name="idno"
                    value="<?php print(htmlspecialchars($_REQUEST['idno'])); ?>"
                    maxlength="20" />
                    <br />
     <label for="email"><strong>Your email address</strong>:</label><br />
           <input type="text"
                    id="email"
                    name="email"
                    value="<?php print(htmlspecialchars($_REQUEST['email'])); ?>" />
                    <p />
<strong>Your message</strong>:<br />
     <label for="comments">
           <textarea id="comments"
                       name="comments"
                       cols="63"
                       rows="9">
                       <?php print(htmlspecialchars($_REQUEST['comments'])); ?>
           </textarea>
     </label>
<p />

           <input type="image"
                    src="../images/send_mail.gif"
                    value=""
                    alt="Click here to send message"
                    title="Click here to send message" />

</form>
     
       <?php

       }

       ?>

And it worked fine for me. For most other people, we had to clear the temporary files, cookies and history before we got the actual form part to load, and then if they sent a message using it, after that they had to go through the process again.

The working form is online here:

http://www.bolton.ac.uk/learningv2/mailforms/paula.php

Thanks a lot for any help you can give me. I loved the course - it's just a matter of getting to grips with it all now But my colleagues are hoping I can get this facet of our site working quite soon, so any and all advice will be most welcome!

Thanks & best wishes,

Paula

Posted by admin (Graham Ellis), 8 September 2005
Your

Code:
if ($_REQUEST)


Says if there's *any* POST data, or *any* GET data, or *any* Cookies ... that an email should be sent.

As a firrt step,   add

Code:
<input name="step" value="1" type="hidden" />


to your form and change the condition to

Code:
if ($_REQUEST[step] == 1)


and that should help you more on ...

Posted by paula (paula), 12 September 2005
That's great, thanks a lot

To be honest, I couldn't get my head round that hidden input thing in the example. It made complete sense while I was watching you put it all together, but when I went away to try it myself, I couldn't really suss it.

It makes a lot more sense now. Thanks!

Paula



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho