11Tami Posted January 10, 2008 Share Posted January 10, 2008 Hello, I'm trying to switch to different text on every next page load. So the text below, "something" on one page load and "something else" on another page load. But this isn't working. Can someone please help me fix this? Please let me know its appreciated, thank you very much. <?php $switching = (isset($_COOKIE['toggle3']) and $_COOKIE['toggle3'] == 1) ? 1 : -1; setcookie('toggle3', $switching, 0); switch($switching) { case 1: echo "Something"; break; case -1: echo "Something else"; $switching *= -1; } ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted January 10, 2008 Share Posted January 10, 2008 session_start(); switch ($SESSION['num']) { case "1": echo "2nd visit"; $SESSION['num'] = $SESSION['num'] + 1; break; case "2": echo "3rd visit"; $SESSION['num'] = $SESSION['num'] + 1; break; default: echo "first visit"; $SESSION['num'] = 1; } Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 10, 2008 Author Share Posted January 10, 2008 Thanks a lot for the help but I think I still need a cookie. Cause it needs to remember what it saw the time before until the next visit, not to forget soon after the browser closes. I just hadn't put the expiration in the first one yet. Unless someone can tell me why I'm wrong. Please keep all the ideas coming, I really need a fix, thank you very much. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 Then just replace papaface's code with cookies instead of sessions and take out the session_start() line. Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 10, 2008 Author Share Posted January 10, 2008 Thanks a lot, I need it so that if it picked from array one randomly the first time, next time it will pick from array two. How do I write that? Please let me know, thank you very much. <?php ini_set('error_reporting', 8191); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); $one = Array(); $one[1] = "test"; $two = Array(); $two[1] = "test2"; $get = shuffle($one,$two); echo $get; ?> Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 10, 2008 Author Share Posted January 10, 2008 Anyone know? I can add the cookie to it, I just need to set up the rest. Thanks. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 10, 2008 Share Posted January 10, 2008 Anyone know? I can add the cookie to it, I just need to set up the rest. Thanks. Define "set up the rest." Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 10, 2008 Author Share Posted January 10, 2008 I'm bringing it back to basics first to get the first part working, then I'll try to get the second working after that so here's what I have. PHP Code: <? php $one = Array(); $one[1] = "test1"; $one[2] = "test2"; $one[3] = "test3"; $one[4] = "test4"; $get = array_rand($one); echo $get; ?> Instead of showing "test1" ect. its only showing 1,2,3, or 4. Anyone know why? Thanks a lot. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 11, 2008 Share Posted January 11, 2008 Try echo $one[$get]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.