Forum Moderators: coopster

Message Too Old, No Replies

Wasted Time Counter

         

JAB Creations

5:28 am on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
if (!isset($_GET['number'])) {$a = 1;}
else {$a = $_GET['number'] + 1;}

$b = $a+ 1;

$self = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?number='.$a;
header("refresh: 1; url=$self");

echo 'You have wasted '.$a.' seconds of your life.';
?>

...at what point should the feeling of concern kick in?

- John

mikhaill

6:31 am on Apr 2, 2008 (gmt 0)

10+ Year Member



Besides the variable $b you never use for anything and since you have the echo after header() call the output will never be seen.. I'd say 35 seconds.

PHP_Chimp

9:59 am on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<?php
if (!isset($_GET['number'])) {$a = 1;}
else {$a = $_GET['number'] + 1;}
if ($a > 35) {
echo 'Dont you have something better to do with your life?';
}
else {
echo "You have wasted $a seconds of your life.";
}
$self = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?number=$a";
header("refresh: 1; url=$self");
?>

How about this ;)

mikhaill

4:36 pm on Apr 2, 2008 (gmt 0)

10+ Year Member



Almost but you're going to get can't sent headers, text already sent error. You can't echo anything before the header() call....

PHP_Chimp

5:38 pm on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



O the irony of writing another reply about waisting time :D

<?php
if (!isset($_GET['number'])) {$a = 1;}
else {$a = $_GET['number'] + 1;}
$self = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?number=$a";
if ($a > 35) {
die ('Dont you have something better to do with your life?');
}
else {
header("refresh: 1; url=$self");
echo "You have wasted $a seconds of your life.";
}
?>

<edit>
If we are going to do this properly then I have changed the code a little.
As there is no point in continuing the loop past 35.

[edited by: PHP_Chimp at 5:41 pm (utc) on April 2, 2008]

JAB Creations

6:40 pm on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool ideas for my waste of code. ;) I like the 35 second time limit the most though I can't seem to grasp why. I realized about the $b only after mikhaill mentioned it though I was happy to get it to work as it was late for me when I wrote it. We just had a PHP Meetup group for the first time in this retirement town so I thought it might be something constructive at least for learning when I show it to new members. :)

- John