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.