keepAway Posted April 7, 2011 Share Posted April 7, 2011 Probably i`m the newbiest guy around here, so i have some questions for you guys. I have the following code: <?php $urna=array(0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"); $culoare="#"; for ($i=1; $i<=6; $i++) $culoare.=$urna[rand(0,15)]; ?> <body bgcolor="<?php echo $culoare;?>"> <form method=post> <input type="submit" name="submit" value="Schimba culoarea" /> </form> Now, i need to "count" how many times the "submit" button has been hit, and for every 4 hits the color will be changed. So, anyone have any clue how could i do that? Link to comment https://forums.phpfreaks.com/topic/233023-count-how-many-times-the-submit-button-has-been-hit/ Share on other sites More sharing options...
dawsba Posted April 8, 2011 Share Posted April 8, 2011 i have no idea why you would want to, but hey cool lol i think youd be better using sessions as they transcend the refresh <?php session_start(); $urna=array(0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"); $cs="#"; if($_SESSION['hit']>=4) { for ($i=1; $i<=6; $i++) { $b .= $urna[rand(0,15)]; } $_SESSION['culoare'] = $cs.$b; } else { $_SESSION['hit']++; } ?> <body bgcolor="<?php echo $_SESSION['culoare']; ?>"> <form method=post> <input type="submit" name="submit" value="Schimba culoarea" /> </form> Link to comment https://forums.phpfreaks.com/topic/233023-count-how-many-times-the-submit-button-has-been-hit/#findComment-1198506 Share on other sites More sharing options...
kenrbnsn Posted April 8, 2011 Share Posted April 8, 2011 This code works: <?php session_start(); $urna=array_merge(range(0,9),range('a','f')); $_SESSION['hit'] = (!isset($_SESSION['hit']))?0:$_SESSION['hit']+1; if(($_SESSION['hit'] % 4) == 0) { shuffle($urna); $_SESSION['culoare'] = '#' . implode('',array_slice($urna,0,6)); } ?> <html> <head> <title>Random Background</title> </head> <body style="background-color:<?php echo $_SESSION['culoare']; ?>"> <?php echo '<pre>' . print_r($_SESSION,true) . '</pre>'; ?> <form method=post> <input type="submit" name="submit" value="Schimba culoarea" /> </form> </html> Ken Link to comment https://forums.phpfreaks.com/topic/233023-count-how-many-times-the-submit-button-has-been-hit/#findComment-1198570 Share on other sites More sharing options...
keepAway Posted April 8, 2011 Author Share Posted April 8, 2011 This code works: <?php session_start(); $urna=array_merge(range(0,9),range('a','f')); $_SESSION['hit'] = (!isset($_SESSION['hit']))?0:$_SESSION['hit']+1; if(($_SESSION['hit'] % 4) == 0) { shuffle($urna); $_SESSION['culoare'] = '#' . implode('',array_slice($urna,0,6)); } ?> <html> <head> <title>Random Background</title> </head> <body style="background-color:<?php echo $_SESSION['culoare']; ?>"> <?php echo '<pre>' . print_r($_SESSION,true) . '</pre>'; ?> <form method=post> <input type="submit" name="submit" value="Schimba culoarea" /> </form> </html> Ken Thanks Ken, thanks dawsba Link to comment https://forums.phpfreaks.com/topic/233023-count-how-many-times-the-submit-button-has-been-hit/#findComment-1198609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.