I can set cookies using setcookie function. If I submit a form, then setcookie doesn't work. The function is called but I don't get any cookie.

<?php
/*
Plugin Name: DoSomething
Version: 0.1
*/

class DoSomething
{
    public function displayForm()
    {
        if (!isset($_COOKIE['do-something'])) {
            require_once('form.php');
        }
    }

    public function formSubmission()
    {
        if (isset($_POST) && !empty($_POST)) {
            // do something here...
        }
    }

    public function skip()
    {
        if (isset($_GET['do-something'])) {
            self::cookies();
        }
    }

    public function cookies()
    {
        $url = parse_url(get_bloginfo('url'));
        setcookie(
            'do-something',
            TRUE,
            3600,
            $url['path'],
            $url['host']
        );
    }
}

add_action('init', array('DoSomething', 'skip'));
add_action('init', array('DoSomething', 'formSubmission'), 1);
add_action('wp_loaded', array('DoSomething', 'displayForm'));
?>

I don't know what to do. Can you help me, please? Thanks.

UPDATE: I've used $_SESSION instead and now it's working. Pretty weird :S Thanks.

link|improve this question
feedback

closed as too localized by Rarst Oct 18 '11 at 20:40

This question is unlikely to ever help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. See the FAQ for guidance on how to improve it.