Jump to content

setting counter back to date('z')


dekonstruct

Recommended Posts

I'm having problems setting $_SESSION['dailies'] back to the date when it gets to 0.

Here's my code:
[code]<?php

session_start();

$date = date('z');

###counter###

if(isset($_SESSION['counted'])){
$new = $_SESSION['counted'] - 5;
$_SESSION['counted'] = $new;
}else {
$_SESSION['counted'] = 0;
}

#########

### supposed to set counter back to date ###

if ($_SESSION['dailies'] <= 0) {
$_SESSION['dailies'] = date('z');
}

else {
$_SESSION['dailies'] = $date + $_SESSION['counted'];
echo $_SESSION['dailies'];
}


?>

[/code]

I think it might have something to do with the placement of my if statement in the code but I've tried it both before and after the counter function. BAH!

Any help and I'll love you forever. (in a non brokeback kind of way).


Link to comment
https://forums.phpfreaks.com/topic/30923-setting-counter-back-to-datez/
Share on other sites

I first define $_SESSION['dailies']; in the else part with:
[code]$_SESSION['dailies'] = $date + $_SESSION['counted'];[/code]

It's so that when the page first loads it's at 0 and when it refreshes it counts down from the day. If there's a better way to do it I'm all ears, it feels like an ineloquent solution but I'm still learning obviously.

Thanks!

Archived

This topic is now archived and is closed to further replies.

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