Jump to content

switching text


11Tami

Recommended Posts

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;
} 
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.