Opinions of Peter Belmont
Speaking Truth to Power
 
.
.
 

Detect if cookies are enabled in PHP scripts

by Peter A. Belmont / 2014-01-06
© 2014 Peter Belmont


  Many web-pages are coded as PHP scripts which run on the web-server and produce HTML text as output. It is this HTML text which is transmitted over the internet to the user’s browser.

It is often important for the PHP script to discover (detect) whether or not the user-browser has COOKIES ENABLED.

This is very easy to determine in PHP.

Let us assume your script is a singlet (i.e., that it consists of a single php script) named: myprog.php.

Rename myprog.php as myprog2.php. Create a new myprog.php and edit these scripts as follows:

myprog.php:
<?php
setcookie(“testcookie”,’123’);
header(“Location: myprog2.php”);
die();
?>

myprog2.php:
<?php
if($_COOKIE[’testcookie’]<>’123’)
{print(“THIS PROGRAM REQUIRES THAT COOKIES BE ENABLED.”); die();}

etc etc etc.




RSS

Recent Essays (All Topics)
 
•(05/25) Thoughts on a Possible USA-Iran War
•(05/25) Is Israel Dying?
•(04/25) Musings on Israel's and the USA's "Right to Exist"
•(04/25) My "take" on BIG-MONEY's responsibility for today's transformation of USA into a Banana Republic
•(03/25) A Legal Brief Supporting Mahmoud Khalil
•(02/25) Response to Peter Beinart's Preference for 1SS over 2SS
•(12/24) What is Fascism?
•(12/24) Contrasting Two Theories of Climate Change, Especially Sensitivity to Excess Atmospheric CO2
•(12/23) How did we get to October 7th?
•(11/23) Our Political Habits Are Ending The Human Race

Comments:

Submit a comment, subject to review:

    Screen Name (Required)
    Commenter's Email (Required)
    Commenter's Blog (Optional)
     

      qqqqqqqqqq
      1234567890

From the preceding TOP string, select as the Verification Code,
fi9fth through te9nth letters
(using the BOTTOM string for reference) and enter it in the slot below
    Verification Code (Required)
  Comment
 
 


123pab.com | Top
©2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 www.123pab.com