CAT | PHP
Traditionally HTTP is a stateless protocol. That is it is made up of requests and responses and there is no notion of a ‘persistent connection’. This means that there is no way to have consistency or personalisation on the web since there is no way of knowing whom the request came from.
There are 2 primary methods – regardless of platform – that are used as a work-around for this.
First is a cookie. A cookie is a text file that lives on the client’s computer that store values set by your application. In general the file can only be access by the website/domain that issued it. The main problem with cookies is that they are un-trusted. A malicious user could modify the data and cause you problems!
The second – and better – solution is sessions. Similar to cookies, but they reside on the server, and cannot be directly modified by the client. When sessions are used, a cookie is still issued, but this simply holds the ‘session id’. This session id is generally sent by any request after it is created by the app including actions such as form submission. This ‘session id’ is a link to either a file or record on the server – depending how they are stored.
AJAX is great… but sometimes it’s too quick if you’re updating… So… How can I make the page wait for a few seconds, then proceed?
Well there are 2 functions PHP has to pause execution. They are:
sleep(NUMBER_OF_SECONDS);
and:
usleep(NUMBER_OF_MS);
One thing you may want to keep in mind is that if you are using a for loop and wish to do this, then you might want to increase the timeout:
set_time_limit(NUMBER_OF_SECONDS);
17
PHP – Generate/Create strong passwords, uuid, random string
0 Comments | Posted by Brian M McGarvie in PHP
>edfa often the need to create passwords or some other ‘unique’ string be it a captcha or for use as unique identifier (UUID).
Here are a few functions I’ve used and refined over the years, 2 types, for password/random string generation and UUID generation.
Generating random strings is pretty simple as it’ll be a password.
However for a UUID there is always the slim chance it’s not unique.
If you are a professional developer (or aspiring) you will inevitably get asked to customise or even better “extend” existing wares.
If it’s a product you are familiar with great! If not I heartilly reccomend spending a little time investigating prior to accepting a job ( ultimatley if they are happy to give
access to their code, if not atleast tell you what’s been used so you cam repliocate it to play with briefly). I know this sounds like a lot of work wich ultimatley – if you
don’t accept the job – you have done for free, but it will save you masses of grief, tears and late nights if you do.
So, I have a few pointers to ‘be aware of’ while evaluating the job and to (generally) identify crappy PHP products/solutions quickly…
A question I am always asked is about ’self-submitting’ forms.
(more…)