Bobscrachy Posted December 15, 2007 Share Posted December 15, 2007 My goal is to have a set number of cascading style sheets which randomly execute with a refresh of a webpage. The hitch I'm having is that i want to set the array of css files to be bounded by a certain number of times the page is refreshed. I thought I could do this with just php, but all I'm coming up with is just creating a random css display script without a bound on the number of refreshes. How do I bound it by the number of refreshes? <?php $sheetx[0] = "black"; $sheetx[1] = "blue"; $sheetx[2] = "blue"; $sheetx[3] = "black"; $sheetx[4] = "blue"; $sheetx[5] = "black"; $sheetx[6] = "red"; $sheetx[7] = "blue"; $sheetx[8] = "red"; $sheetx[9] = "black"; $number = 0; $minus = 1; $fifteen = 9; $css = ".css"; while ($number <= { echo "<br>"; $number = $number + 1; } $random_number = rand(0,$number); echo "$random_number"; echo "<br>"; echo "<br>"; echo "http://domain/icons/$sheetx[$random_number]".$css; ?> -Bob Quote Link to comment Share on other sites More sharing options...
papaface Posted December 15, 2007 Share Posted December 15, 2007 Use sessions. These will help: session_start(); $_SESSION['refreshno'] = $_SESSION['refreshno']++; if ($_SESSION['refreshno'] > 10) { //do code to load a new CSS } Quote Link to comment Share on other sites More sharing options...
Bobscrachy Posted December 15, 2007 Author Share Posted December 15, 2007 I know its a syntax error. I'm not familiar with the in and outs of sessions. <?php session_start(); $_SESSION['refreshno'] = $_SESSION['refreshno']++; $sheetx[0] = "black"; $sheetx[1] = "blue"; $sheetx[2] = "blue"; $sheetx[3] = "black"; $sheetx[4] = "blue"; $sheetx[5] = "black"; $sheetx[6] = "red"; $sheetx[7] = "blue"; $sheetx[8] = "red"; $sheetx[9] = "black"; $number = 0; $minus = 1; $fifteen = 9; $css = ".css"; while ($number <= { echo "<br>"; $number = $number + 1; } $random_number = rand(0,$number); echo "<br>"; echo "<br>"; if ($_SESSION['refreshno'] > 10) { echo "http://domain/icons/$sheetx[$random_number]".$css; else $_SESSION['refreshno'] = 1; echo "refreshno= ". $_SESSION['refreshno']; ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted December 15, 2007 Share Posted December 15, 2007 You missed a } Quote Link to comment Share on other sites More sharing options...
Bobscrachy Posted December 16, 2007 Author Share Posted December 16, 2007 I've written it, but now there is a different problem. For some reason the variables below line 41 aren't executing. Since its the second part of my while statement the script gives out after 15 refreshes. Do you have any suggestions? <?php session_start(); $_SESSION['views'] = $_SESSION['views'] + 1; if ($_SESSION['views'] < 15) { $sheetx[0] = "black"; $sheetx[1] = "blue"; $sheetx[2] = "blue"; $sheetx[3] = "black"; $sheetx[4] = "blue"; $sheetx[5] = "black"; $sheetx[6] = "red"; $sheetx[7] = "blue"; $sheetx[8] = "red"; $sheetx[9] = "black"; $random_text[0] = "TEXT0"; $random_text[1] = "TEXT1"; $random_text[2] = "TEXT2"; $random_text[3] = "TEXT3"; $random_text[4] = "TEXT4"; $random_text[5] = "TEXT5"; $random_text[6] = "TEXT6"; $random_text[7] = "TEXT7"; $random_text[8] = "TEXT8"; $random_text[9] = "TEXT9"; //line 28 $number = 0 + $_SESSION['views']; $css = ".css"; if ($number <= 15) {$random_number = rand(0,$number); echo "<head> <link rel=\"stylesheet\" type=\"text/css\" href=\"http://domain/icons/$sheetx[$random_number]$css\"/> </head>"; echo "$random_text[$random_number]";} else //line 41 { echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"http://bobscrachy.redirectme.net/icons/".$sheetx[2].$css."/></head>"; echo $random_text[2];} } else { echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"http://bobscrachy.redirectme.net/icons/$sheetx[2]$css\"/></head>"; echo $random_text[2];}?> Quote Link to comment Share on other sites More sharing options...
Bobscrachy Posted December 16, 2007 Author Share Posted December 16, 2007 Solved Thank you for the help guys. <?php session_start(); $_SESSION['views'] = $_SESSION['views'] + 1; $number = 0 + $_SESSION['views']; $css = ".css"; $sheetx[0] = "black"; $sheetx[1] = "blue"; $sheetx[2] = "blue"; $sheetx[3] = "black"; $sheetx[4] = "blue"; $sheetx[5] = "black"; $sheetx[6] = "red"; $sheetx[7] = "blue"; $sheetx[8] = "red"; $sheetx[9] = "black"; $random_text[0] = "TEXT0"; $random_text[1] = "TEXT1"; $random_text[2] = "TEXT2"; $random_text[3] = "TEXT3"; $random_text[4] = "TEXT4"; $random_text[5] = "TEXT5"; $random_text[6] = "TEXT6"; $random_text[7] = "TEXT7"; $random_text[8] = "TEXT8"; $random_text[9] = "TEXT9"; if ($number <= 15) {$random_number = rand(0,$number); echo "<head> <link rel=\"stylesheet\" type=\"text/css\" href=\"domain/icons/$sheetx[$random_number]$css\"/> </head>"; echo "$random_text[$random_number]";} else { echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"domain/icons/" .$sheetx[2] .$css. "/></head>"; echo $random_text[2];} ?> 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.