-1

First Page: I have a form that links to the second page when the submit button is pushed.

<form action='http://localhost/wordpress/secondpage/' method='get'>
    <input class='changeDataButtons' type='submit' name='activate' value='Activate' />
</form>"; 

Second Page: I check if the "Activate" button was pushed and I activate a second menu in my wordpress site.

if(isset($_GET['activate']))
{
    my_wp_nav_menu_args();
}
function my_wp_nav_menu_args($args = '')
{
    $args['menu'] = 'Menu 2';
    return $args;                           
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

I also have a form in the second page that link to the first page when the submit button is pushed.

<form action='http://localhost/wordpress/firstpage' method='get'>
    <input class='changeDataButtons' type='submit' name='deactivate' value='Deactivate' />
</form>";

First Page: I check if the "Deactivate" button was pushed and I activate the first menu in my wordpress site.

if(isset($_GET['deactivate']))
{
    my_wp_nav_menu_args();
}
function my_wp_nav_menu_args($args = '')
{
    $args['menu'] = 'Menu 1';
    return $args;                           
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

Everything works fine but when I close the browser, $_GET gets to zero and Menu 1 is activated again. Is there a way to keep $_GET value? I thought about using sessions and set a cookie with an expire time, but I don't want it to expire. Thanks in advance.

Kiki
  • 75
  • 1
  • 1
  • 7

3 Answers3

1

Sessions and cookies are the best way to do it and make sure they do not expire. The 3rd option would be to grab the IP address and save it to a database with those options set.

kayleighsdaddy
  • 670
  • 5
  • 15
  • How can I make sure that they do not expire? – Kiki Aug 25 '15 at 15:18
  • cookie never expire: setcookie("CookieName", "CookieValue", 2147483647); – kayleighsdaddy Aug 25 '15 at 15:24
  • Sessions never expire: session_set_cookie_params(2147483647); – kayleighsdaddy Aug 25 '15 at 15:26
  • $_SERVER['REMOTE_ADDR'] to get the persons IP address. Then you can save it into a database. This is often used for much more secure logins. – kayleighsdaddy Aug 25 '15 at 15:28
  • Don't rely on IP address (neither on any `$_SERVER` variable) to identify a user. It can be an interesting data (warn a user that someone logged-in to his/her account with an unknow IP for example), but don't rely on it. –  Aug 25 '15 at 15:34
0

Try this,

setcookie("name", "value", time() * 2, "/");

That will expire on Mon, 18 Apr 2061 06:46:52 GMT

Script47
  • 14,230
  • 4
  • 45
  • 66
-1

I would use a session. If session = true, page = 2 else page = 1

Bernhard
  • 1,852
  • 11
  • 19