setcookie example

    // decided to only set sessions when absolutely necessary (e.g., to increase     // anonymous user cache hit rates) and as such we cannot use the Symfony     // convenience method here.     session_destroy();

    // Unset the session cookies.     $session_name = $this->getName();
    $cookies = $this->requestStack->getCurrentRequest()->cookies;
    // setcookie() can only be called when headers are not yet sent.     if ($cookies->has($session_name) && !headers_sent()) {
      $params = session_get_cookie_params();
      setcookie($session_name, '', REQUEST_TIME - 3600, $params['path']$params['domain']$params['secure']$params['httponly']);
      $cookies->remove($session_name);
    }
  }

  /** * {@inheritdoc} */
  public function setWriteSafeHandler(WriteSafeSessionHandlerInterface $handler) {
    $this->writeSafeHandler = $handler;
  }

  
/* * We send an invalidation Set-Cookie header (zero lifetime) * when either the session was started or a cookie with * the session name was sent by the client (in which case * we know it's invalid as a valid session cookie would've * started the session). */
            if (null === $cookie || isset($_COOKIE[$this->sessionName])) {
                $params = session_get_cookie_params();
                unset($params['lifetime']);
                setcookie($this->sessionName, '', $params);
            }
        }

        return $this->newSessionId === $sessionId || $this->doDestroy($sessionId);
    }
}
$this->cookieSecure = $cookie->secure;

        $this->ipAddress = $ipAddress;
    }

    /** * Internal method to force removal of a cookie by the client * when session_destroy() is called. */
    protected function destroyCookie(): bool
    {
        return setcookie(
            $this->cookieName,
            '',
            ['expires' => 1, 'path' => $this->cookiePath, 'domain' => $this->cookieDomain, 'secure' => $this->cookieSecure, 'httponly' => true]
        );
    }

    /** * A dummy method allowing drivers with no locking functionality * (databases other than PostgreSQL and MySQL) to act as if they * do acquire a lock. */
    

function wp_set_comment_cookies( $comment$user$cookies_consent = true ) {
    // If the user already exists, or the user opted out of cookies, don't set cookies.     if ( $user->exists() ) {
        return;
    }

    if ( false === $cookies_consent ) {
        // Remove any existing cookies.         $past = time() - YEAR_IN_SECONDS;
        setcookie( 'comment_author_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN );
        setcookie( 'comment_author_email_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN );
        setcookie( 'comment_author_url_' . COOKIEHASH, ' ', $past, COOKIEPATH, COOKIE_DOMAIN );

        return;
    }

    /** * Filters the lifetime of the comment cookie in seconds. * * @since 2.8.0 * * @param int $seconds Comment cookie lifetime. Default 30000000. */
<?php
require __DIR__.'/common.inc';

setcookie('abc', 'def');

session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
session_start();
session_write_close();
session_start();

$_SESSION['abc'] = 234;
unset($_SESSION['abc']);


    $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );

    if ( get_option( 'siteurl' ) !== $url ) {
        update_option( 'siteurl', $url );
    }
}

// Set a cookie now to see if they are supported by the browser. $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );

if ( SITECOOKIEPATH !== COOKIEPATH ) {
    setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
}

if ( isset( $_GET['wp_lang'] ) ) {
    setcookie( 'wp_lang', sanitize_text_field( $_GET['wp_lang'] ), 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
}

/** * Fires when the login form is initialized. * * @since 3.2.0 */
wp_die( __( 'A key value mismatch has been detected. Please follow the link provided in your activation email.' )__( 'An error occurred during the activation' ), 400 );
} elseif ( ! empty( $_GET['key'] ) ) {
    $key = $_GET['key'];
} elseif ( ! empty( $_POST['key'] ) ) {
    $key = $_POST['key'];
}

if ( $key ) {
    $redirect_url = remove_query_arg( 'key' );

    if ( remove_query_arg( false ) !== $redirect_url ) {
        setcookie( $activate_cookie$key, 0, $activate_path, COOKIE_DOMAIN, is_ssl(), true );
        wp_safe_redirect( $redirect_url );
        exit;
    } else {
        $result = wpmu_activate_signup( $key );
    }
}

if ( null === $result && isset( $_COOKIE[ $activate_cookie ] ) ) {
    $key    = $_COOKIE[ $activate_cookie ];
    $result = wpmu_activate_signup( $key );
    setcookie( $activate_cookie, ' ', time() - YEAR_IN_SECONDS, $activate_path, COOKIE_DOMAIN, is_ssl(), true );
}
/** * Filters the length of time a Recovery Mode cookie is valid for. * * @since 5.2.0 * * @param int $length Length in seconds. */
        $length = apply_filters( 'recovery_mode_cookie_length', WEEK_IN_SECONDS );

        $expire = time() + $length;

        setcookie( RECOVERY_MODE_COOKIE, $value$expire, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true );

        if ( COOKIEPATH !== SITECOOKIEPATH ) {
            setcookie( RECOVERY_MODE_COOKIE, $value$expire, SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl(), true );
        }
    }

    /** * Clears the recovery mode cookie. * * @since 5.2.0 */
    

        setrawcookie($name$value$options);
    }

    /** * Extracted call to `setcookie()` in order to run unit tests on it. * * @codeCoverageIgnore */
    private function doSetCookie(string $name, string $value, array $options): void
    {
        setcookie($name$value$options);
    }

    /** * Force a download. * * Generates the headers that force a download to happen. And * sends the file to the browser. * * @param string $filename The name you want the downloaded file to be named * or the path to the file to send * @param string|null $data The data to be downloaded. Set null if the $filename is the file path * @param bool $setMime Whether to try and send the actual MIME type * * @return DownloadResponse|null */
<?php
require __DIR__.'/common.inc';

session_set_save_handler(new TestSessionHandler('abc|i:123;'), false);
session_start();

setcookie('abc', 'def');
wp_update_attachment_metadata( $post_id$newmeta );

        // Intentional fall-through to trigger the edit_post() call.     case 'editpost':
        check_admin_referer( 'update-post_' . $post_id );

        $post_id = edit_post();

        // Session cookie flag that the post was saved.         if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
            setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() );
        }

        redirect_post( $post_id ); // Send user on their way while we keep working.
        exit;

    case 'trash':
        check_admin_referer( 'trash-post_' . $post_id );

        if ( ! $post ) {
            wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
        }


    /** * Extracted call to `setcookie()` in order to run unit tests on it. * * @codeCoverageIgnore * * @deprecated */
    protected function setCookie(string $name, string $value, array $options): void
    {
        setcookie($name$value$options);
    }
}

        // check URL debugging control         if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {
            if (isset($_SERVER['QUERY_STRING'])) {
                $_query_string = $_SERVER['QUERY_STRING'];
            } else {
                $_query_string = '';
            }
            if (false !== strpos($_query_string$this->smarty->smarty_debug_id)) {
                if (false !== strpos($_query_string$this->smarty->smarty_debug_id . '=on')) {
                    // enable debugging for this browser session                     setcookie('SMARTY_DEBUG', true);
                    $this->smarty->debugging = true;
                } elseif (false !== strpos($_query_string$this->smarty->smarty_debug_id . '=off')) {
                    // disable debugging for this browser session                     setcookie('SMARTY_DEBUG', false);
                    $this->smarty->debugging = false;
                } else {
                    // enable debugging for this page                     $this->smarty->debugging = true;
                }
            } else {
                if (isset($_COOKIE['SMARTY_DEBUG'])) {
                    

        if ( ! apply_filters( 'send_auth_cookies', true, $expire$expiration$user_id$scheme$token ) ) {
            return;
        }

        setcookie( $auth_cookie_name$auth_cookie$expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true );
        setcookie( $auth_cookie_name$auth_cookie$expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true );
        setcookie( LOGGED_IN_COOKIE, $logged_in_cookie$expire, COOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true );
        if ( COOKIEPATH != SITECOOKIEPATH ) {
            setcookie( LOGGED_IN_COOKIE, $logged_in_cookie$expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure_logged_in_cookie, true );
        }
    }
endif;

if ( ! function_exists( 'wp_clear_auth_cookie' ) ) :
    /** * Removes all of the cookies associated with authentication. * * @since 2.5.0 */
/* * We send an invalidation Set-Cookie header (zero lifetime) * when either the session was started or a cookie with * the session name was sent by the client (in which case * we know it's invalid as a valid session cookie would've * started the session). */
            if (null === $cookie || isset($_COOKIE[$this->sessionName])) {
                $params = session_get_cookie_params();
                unset($params['lifetime']);
                setcookie($this->sessionName, '', $params);
            }
        }

        return $this->newSessionId === $sessionId || $this->doDestroy($sessionId);
    }
}
Home | Imprint | This part of the site doesn't use cookies.