Jump to content

Count how many times the submit button has been hit


keepAway

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.