简体   繁体   中英

Set cookie from Checkbox to skip landing page

I've made a website with a landing page.

I want to set up a checkbox to skip the landing page, directly to the homepage, the next time the user comes to the website.

How can I add a cookie to the checkbox to do what I need?

Thank you very much!

You could use a session to do that.

by setting

$_SESSION['skip_intro'] = true;

once the checkbox has been used.

If you need a method to implement that action, you could make your checkbox form use a form with method="GET" and send it to your homepage.

Then you could process that on your homepage with something along the lines of:

if (isset($_GET['always_skip']) && $_GET['always_skip'] == true) {
    $_SESSION['skip_intro'] = true;
}

[assuming your checkbox has name="always_skip" attached to it.]

You could then check on your intro page whether to play the intro or skip it:

if (isset($_SESSION['skip_intro']) && $_SESSION['skip_intro'] == true) {
     //skip intro
     header: ("location: homepage.php");
} else {
     //play intro
}

Here's what I think you need to look into:

http://php.net/setcookie This will let you set the cookie if the check box is checked on submit. http://php.net/manual/en/reserved.variables.cookies.php This will tell you how to access the cookie data to check if you need to skip the landing page.

If you want to skip the page, then use header to redirect the page. http://php.net/manual/en/function.header.php

Basic and no JavaScript required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM