PHP script to check cookie existence and display a message
Write a PHP script to check if a cookie named "visited" exists. If it does, display a welcome message; otherwise, display a default message.
Sample Solution:
PHP Code :
<?php
$cookieName = "visited";
if (isset($_COOKIE[$cookieName])) {
echo "Welcome back! You have visited before.";
} else {
echo "Welcome! This is your first visit.";
}
?>
Sample Output:
Welcome! This is your first visit.
Flowchart:
PHP Code Editor:
Contribute your code and comments through Disqus.
Previous: Set a secure PHP cookie for an encrypted connection.
Next: PHP script to store user preferences in a session variable.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics