So I've made a page load counter. I don't know or remember if that's what they're actually called, but that's at least what I'm calling it. It's purpose is to basically set a number of views, then each time you click a button it reduces the number by one, and displays a new message tied to that number. The code is ugly because I worked on it a long time ago and I'm just getting back into coding again, and want to make it ac least function before I go through and rearrange it into an array and further modify the code. But the simple problem that I'm noticing is that it's just not reducing the number, and I'm not sure if it's because it's not setting the session, or if there's something I'm just missing. So here it is, hopefully someone can help me. Thanks in advance for any assistance offered.
<?php
session_start();
if($_GET['refresh']){
$_SESSION['views'] = 21;
}
if(!isset($_SESSION['views'])){
$_SESSION['views'] = 21;
}
if($_SESSION['views'] == 21){
echo "<h3>Oh. Hello there. How'd you get in here?
Oh well, just please don't push that button, okay?</h3>";
echo "<br/>";
}
if($_SESSION['views'] == 20){
echo "<h3>What are you doing?! I just said not to touch that!
Leave it alone now!</h3>";
}
if($_SESSION['views'] == 19){
echo "<h3>Stop! Are you trying to kill us all?! Get away from there!</h3>";
}
if($_SESSION['views'] == 18){
echo "<h3>Okay, let's start over. We're obviously off to a bad start.
Hi. My name's Tim. I work at this lab and it's my job to ensure that
button is never pressed.</h3>";
}
if($_SESSION['views'] == 17){
echo "<h3>Ha..Ha..Ha.. Okay now. Don't do anything hasty. What's got
you feeling so down that you want to go and kill everyone, huh?</h3>";
}
if($_SESSION['views'] == 16){
echo "<h3>Please stop pushing that button. Talk to me. Tell me
what's wrong buddy. I won't judge you, I swear.</h3>";
}
if($_SESSION['views'] == 15){
echo "<h3>Come now. What could possibly be so bad that you'd want to
kill everything? Is life really so hard? Why won't you speak to me?</h3>";
}
if($_SESSION['views'] == 14){
echo "<h3>I'm sorry but if you continue pressing that button, I'm going
to call security and have you forcibly removed from the premisis.</h3>";
}
if($_SESSION['views'] == 13){
echo "<h3>What's this? So you don't believe I'll actually do it? Fine.
GUARDS! Come quick! There's a maniac in here trying to destroy us all!</h3>";
}
if($_SESSION['views'] == 12){
echo "<h3>Well I hope you're happy. I don't like being the mean guy, you know?
I just wanted to be friendly, I don't get any visitors. But now look what
you've gone and made me do. They should be here any minute now.</h3>";
}
if($_SESSION['views'] == 11){
echo "<h3>Would you stop hitting that button already? It's over. They're coming
to get you and take you away. You're most likely going to be sent to a
maximum security prison for breaking in here you know.</h3>";
}
if($_SESSION['views'] == 10){
echo "<h3>Yup. Any minute now. So you might as well stop hitting that button.
The jig is up. I think I hear them now. It sounds like they're carrying some big guns too.
I'd suggest just laying down and giving up now. But no, you just keep on hitting
that stupid little button.</h3>";
}
if($_SESSION['views'] == 9){
echo "<h3>Okay, stop. This is getting ridiculous. Just give it up and relax
while you wait for my guards to take you away. They'll be here any second.
Any second now.</h3>";
}
if($_SESSION['views'] == {
echo "<h3>Yup. Any time now..</h3>";
}
if($_SESSION['views'] == 7){
echo "<h3>Yup. Any... Okay you got me. I don't have any guards.
But you seriously need to stop hitting that button. Actually, go ahead and hit it.
I don't care anymore. Just keep pressing it. See if I care.</h3>";
}
if($_SESSION['views'] == 6){
echo "<h3>Nope. Go ahead. Push it some more. I wont try to stop you.
It's not like I have anything to live for anyways. I have no wife, no kids.
I live in this lab; that's my bed over there. I've never had a girlfriend,
not even a real job. All I do is sit here and stare at a button all day.</h3>";
}
if($_SESSION['views'] == 5){
echo "<h3>Yeah, that's right. Blow this place up. Kill everything like the
little button pushing demon you truly are.</h3>";
}
if($_SESSION['views'] == 4){
echo "<h3>Wait! I changed my mind! I don't want to die. I want to live.
I want to get a girlfriend. I want kids. I want a house of my own, somewhere off
in the country so my children can run and play all day. Please, if you have any humanity
left in you at all, please don't push that button anymore.</h3>";
}
if($_SESSION['views'] == 3){
echo "<h3>PLEASE! Stop it! Oh god! You won't listen will you?! You're going
to kill all of us! Stop it! Oh god the clicking! I can hear the cliking of that
button in my head! Make it stop! MAKE IT STOP!!</h3>";
}
if($_SESSION['views'] == 2){
echo "<h3>OH GOD!! The noise!! MAKE IT STOP!!! ARRRGH!! ROCK PAPER SCISSORS SHOOT!! What am I saying?! Why are you doing this to me?!
STOP IT!! GET OUT OF MY HEAD!!</h3>";
}
if($_SESSION['views'] == 1){
echo "<h3>ARRRGGGGH!!!! I'M GOING TO KILL YOU ALL!! STOP THE NOISE!!!! I CAN HEAR IT!! YOU'RE DOING THIS TO ME!!! STOP IT!!!!</h3>";
}
if($_SESSION['views'] == 0){
echo "<h3>GRAHH!! DIE! DIE! DIE! *Tim charges you and tackles you to the ground. As you black out from the heavy head impact the last thing you see
is Tim bearing down on your throat with a scalpel.</h3>";
}
if($_SESSION['views'] > 0){
$_SESSION['views'] -= 1;
echo "Button presses left until the end of the world: " . $_SESSION['views'];
echo "<br/>";
echo "<a href='page_load_counter.php'><button>Launch Missile</button></a>";
echo "<br/>";
}
if($_SESSION['views'] <= 0){
echo "<a href='page_load_counter.php?refresh=1'><button>Reset</button></a>";
}
?>