While time can be taken to automate some function that requires a record of previous visits, generating the cookie responsible for these records may prove more efficient. As cookies are simply text files containing few data fields, they are easy to generate and modify to suit your needs.
The following PHP code provides a straightforward example of a script that may be hosted on the website being tested. This script generates the cookie as defined then redirects to the first page used in your test process.
Cookie generation will accept just a name or a name and any number of additional parameters. These parameters allow an expiration time to be set, a path to be specified and whether or not HTTP/HTTPS is enforced.
$target = $_GET['target']; // Target URL for redirect
$name = "cookiename"; // Stored locally, Retrieve through $_COOKIE['cookiename']
$expire = "expiretime" // Unix timestamp in seconds: time() + (#sec), time()+60*60*24*30 for 30 days, 0 for session
$path = "pathaddress" // The path on the server in which the cookie will be available (/ for domain /dir/ for directories)
$secure = "secureornot" // TRUE for cookie creation only on secure connections
$httponly = "httpornot" // TRUE if cookie will be accessible only via HTTP (not JS)
setcookie($name, $value, $expire, $path, $secure, $httponly); // Generate cookie for all available parameters, remove those not utilized
header('Location: ' $target); exit(); // Redirect to "target" URL given in generator URL
Let’s assume the cookie generating PHP script above is saved as setcookie.php and uploaded to the root directory of yourdomain.com. If you’d like to test yourdomain.com/form, you can enter the following URL into the CBT Live Testing App.
The cookie will be generated upon execution, followed by a redirect to the target URL so that you can get to testing as quickly as possible!
This cookie’s data can be verified in your browser’s developer tools.