Coleman1667 Posted December 26, 2015 Share Posted December 26, 2015 (edited) 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>"; } ?> Edited December 26, 2015 by Coleman1667 Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 26, 2015 Share Posted December 26, 2015  <?php  session_start();  //Define array of messages $messages = array(   "Oh. Hello there. How'd you get in here? Oh well, just please don't push that button, okay?",   "What are you doing?! I just said not to touch that! Leave it alone now!",   "Stop! Are you trying to kill us all?! Get away from there!",   "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.",   "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?",   "Please stop pushing that button. Talk to me. Tell me what's wrong buddy. I won't judge you, I swear.",   "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?",   "I'm sorry but if you continue pressing that button, I'm going to call security and have you forcibly removed from the premisis.",   "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!",   "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.",   "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.",   "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",   "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.",   "Yup. Any time now..",   "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.",   "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.",   "Yeah, that's right. Blow this place up. Kill everything like the little button pushing demon you truly are.",   "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.",   "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!!",   "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!!",   "ARRRGGGGH!!!! I'M GOING TO KILL YOU ALL!! STOP THE NOISE!!!! I CAN HEAR IT!! YOU'RE DOING THIS TO ME!!! STOP IT!!!!",   "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.", );  //Dynamically determine total button presses $totalButtonPresses = count($messages);  //Set starting button presses if needed if(!isset($_SESSION['presses_left']) || isset($_GET['refresh'])){ $_SESSION['presses_left'] = $totalButtonPresses; }  if($_SESSION['presses_left'] > 0) {   //Determine message to display   $messageIndex = $totalButtonPresses - $_SESSION['presses_left'];   echo "<h3>{$messages[$messageIndex]}</h3>";   echo "Button presses left until the end of the world: {$_SESSION['presses_left']}<br/><br/>\n";   //Reduce presses left   $_SESSION['presses_left'] -= 1;   echo "<a href='page_load_counter.php'><button>Launch Missile</button></a><br/>\n"; } else {   echo "<h3>Boom!</h3>";   echo "<a href='page_load_counter.php?refresh'><button>Reset</button></a>"; }  ?>  Quote Link to comment Share on other sites More sharing options...
Coleman1667 Posted December 28, 2015 Author Share Posted December 28, 2015 Thank you for your assistance, but the code you provided still won't function for some reason. Again with your code, kind of like with mine, I can't find any logical reason that it's not working properly. if you'd like to take a look at it on the site then it's here. It seems that it's either setting the count every time you load the page, or it's simply not subtracting from the count at all. IT may be a server side issue but if it is then I'm not sure how to test that. My site is hosted at fatcow, I don't know any known issues with it running PHP but maybe you guys do, I don't know. This is really frustrating and I've tried everything I can think of. Site link for anybody that wants to take a look: http://coleman1667.com/page_load_counter.php Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 28, 2015 Share Posted December 28, 2015 The code I posted above worked for me. Did you add anything else other than what I provided (although I just noticed the code isn't creating a complete, valid HTML page - which would not affect the behavior in question). Is there anything page that includes the script above? Try adding some code to the page to debug the issue (trouble shooting 101). Â Add this to the bottom of the page to see what the data is on each page load: Â Â echo "<b>Debug Code:</b><br><br>\n\n"; echo "<pre>\n"; echo "POST DATA:\n" . print_r($_POST, TRUE) . "\n\n"; echo "GET DATA:\n" . print_r($_GET, TRUE) . "\n\n"; echo "SESSION DATA:\n" . print_r($_SESSION, TRUE) . "\n\n"; echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
Solution Coleman1667 Posted December 28, 2015 Author Solution Share Posted December 28, 2015 Wow, okay. I guess I found the answer to my own question. I'm not gonna mark this answered quite yet, but I found a few sites and instructions on FatCow itself on how to handle the issue. I guess according to (http://theedgeofall.com/journeys/2010/04/21/php-ini-issues-fat-cow-hosting/), FatCow has a number of issues when it comes to PHP files, insofar that their .ini file needs modification. I have the ability to edit my .ini file and to set it to default if I mess something up, so I'm going to follow the instructions this guy provides and match them to the ones FatCow provides and see if that fixes it at all. Will update shortly. Quote Link to comment Share on other sites More sharing options...
Coleman1667 Posted December 28, 2015 Author Share Posted December 28, 2015 Okay, I followed the instructions on the FatCow page and fixed the stupid issue fatcow has by default, and it all works perfectly now. Thank you for your help, really. 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.