Home Accessibility Courses Twitter The Mouth Facebook 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))
Remember Me - PHP

Here's a paradox for you as a web site designer, when putting together a web site which requires a login.

Most of your users are regulars, who really don't want the hassle of logging in every time they visit ... but at the same time, you can't allow blanket, long term logins as your site is often accessed by legitimate users from public access / shared computers on which permanent cookies should not be left.

The solution - and I'm sure most of you will have see it on any number of sites like forums - is a "remember me" box. Simple and easy - your users will be defaulted to a short session of, say, 30 minutes ... but if they check the box, their logins will last for a much longer period.

We use our own web site for much of our internal communications and for our various status pages. With Headquarters, booking and admin office on the outskirts of Melksham, and a Training Centre and Hotel near to the town centre ... and with me often giving On Site Courses many miles from home, this is a key form of communication. From the Admin systems that Lisa runs, from the laptops which are assigned to the rest of us personally, we need to be able to be in touch with a minimum of keystrokes. And we need to be able to check on the status from the reception computer, from trainee laptops, and from the public access system too. It goes even further than that - I need to be able to borrow a customer's keyboard on site (behind the customer's firewall where I cannot have access from my own system!) and still check and update the status.

Until now, we've been very careful to remember to log out from a shared computer ... but there are times that all of us have got called away from such a system - perhaps to carry on with Customer Service which is the reason we logged in, in the first place. So this morning, I've added a "remember me" box into our main login script.


It's in PHP, and the extra code is very straightforward.

The extra check box:

<input name=mine type=checkbox> Remember me!

The code that works out the login period:

$days = 0.02;
if ($_REQUEST[mine] != "") $days = 14;
pwlogin($a,$days);


and the login function that sets the cookie:

function pwlogin($arriving,$days=7) {
global $pwname;
setcookie("whcttt","$arriving:$pwname", time()+3600*24*$days,"/",".wellho.net");
$_COOKIE[whcttt] = "$arriving:$pwname";


The only thing that may be something of a surprise package in that code is the last line - setting the $_COOKIE superglobal to the same value that is being sent out to the browser. That's done to allow the user to be logged in on the current ("congratulations, you have logged in") page as well as on subsequent pages.
(written 2008-11-28, updated 2008-12-01)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H303 - PHP - Long and short term cookies and security
  [1646] Using cookies and sessions to connect different URLs - PHP - (2008-05-18)
  [2238] Handling nasty characters - Perl, PHP, Python, Tcl, Lua - (2009-06-14)
  [3698] How to stop forms on other sites submitting to your scripts - (2012-04-15)
  [3813] Injection Attacks - PHP, SQL, HTML, Javascript - and how to neutralise them - (2012-07-22)

H301 - PHP - Sticky fields and session
  [1739] Bath, Snake or Nag? - (2008-08-06)
  [1766] Diagrams to show you how - Tomcat, Java, PHP - (2008-08-22)
  [2416] Automating access to a page obscured behind a holding page - (2009-09-23)
  [2738] What is all this SESSION stuff about? (PHP) - (2010-04-25)
  [3540] Easy session example in PHP - keeping each customers data apart - (2011-12-06)
  [3820] PHP sessions - a best practice teaching example - (2012-07-27)
  [3918] Multiple page web applications - maintaining state - PHP - (2012-11-10)
  [4070] Passing variable between PHP pages - hidden fields, cookies and sessions - (2013-04-26)


Back to
Java - Generics
Previous and next
or
Horse's mouth home
Forward to
Book now for 2009
Some other Articles
Quietly putting prices up
It must be nearly Christmas
Alastair Darling helps make paperwork and confusion
Book now for 2009
Remember Me - PHP
Java - Generics
javax.servlet cannot be resolved - how to solve
Java CLASSPATH explained
Melksham Hotel Rates
Long, Longer, Longest in Java
4759 posts, page by page
Link to page ... 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 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

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

PAGE: http://www.wellho.info/mouth/1911_Rem ... e-PHP.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb