Click here to Skip to main content
15,881,898 members
Home / Discussions / Web Development
   

Web Development

 
AnswerRe: HI can someone help me with my responsive gallery project? Pin
Member 1529865622-Jul-21 21:56
Member 1529865622-Jul-21 21:56 
QuestionHello, i need some help for a project with css and html Pin
Florina Catalina10-Mar-21 4:38
Florina Catalina10-Mar-21 4:38 
QuestionHelp me remove unused CSS Pin
maithu7029-Mar-21 1:27
maithu7029-Mar-21 1:27 
AnswerRe: Help me remove unused CSS Pin
Richard Deeming9-Mar-21 22:20
mveRichard Deeming9-Mar-21 22:20 
AnswerRe: Help me remove unused CSS Pin
User 1407655214-Jul-21 10:03
User 1407655214-Jul-21 10:03 
QuestionDeployments Pin
#realJSOP27-Feb-21 4:57
mve#realJSOP27-Feb-21 4:57 
QuestionASP.Net Web API Controller Question Pin
Kevin Marois26-Feb-21 7:47
professionalKevin Marois26-Feb-21 7:47 
QuestionPHP7+, working with datetime stored in cookie with json format Pin
jkirkerx17-Feb-21 11:48
professionaljkirkerx17-Feb-21 11:48 
I probably just chose the wrong format to store the datetime in the cookie, but it's worth pursuing time someone tells me to change it.

I need help with converting the date, so I can do a compare or diff, or perhaps dumping the date for something else, or just general help with making this work. Help can just be an idea or nudge. Keep in mind that I'm not a PHP 7 expert, and lost my knowledge of PHP back in 2005 or so. I've been working on this for hours and I'm not sure whether to dump it and start again, or do even more research.
public static function setJsonAuthCookie($userName, $userType): void {

        date_default_timezone_set('America/Los_Angeles');
        $today = new DateTime();

        $jsonData = array(
            "userName" => $userName,
            "userType" => $userType,
            "createdOn" => $today,
            "expires" => $today->add(new DateInterval('PT4H')),
            "token" => "",
            "auth0" => ""
        );

        $jsonEncode = json_encode($jsonData, JSON_FORCE_OBJECT);
        setcookie("authJson", $jsonEncode, time()+240);

    }

    public static function validateUser(): array {

        $cookie = clsAuth::getJsonAuthCookie();
        if (!isset($cookie)) {

            $formAction = "/pcad/unauthorized.phtml";
            header("Location: http://".$_SERVER['HTTP_HOST']."$formAction");

        } else {

            $userName = $cookie['userName'];
            $userType = $cookie['userType'];
            $createdOn = $cookie['createdOn'];
            $expires = $cookie['expires'];
            $token = $cookie['token'];
            $auth0 = $cookie['auth0'];

            // Convert the string date back into a date object
            date_default_timezone_set('America/Los_Angeles');
            $today = new DateTime();
            $dateString = $expires['date'];
            $timeZone = $expires['timezone'];

            echo "<div>validating token</div>";

            if ($dateString > $today) {

                echo "<div>token declined</div>";

                sleep(1);
                $formAction = "/pcad/";
                // header("Location: http://".$_SERVER['HTTP_HOST']."$formAction");

            } else {

                echo "<div>token accepted</div>";

// Cookie Value
%7B%22userName%22%3A%22jimk%22%2C%22userType%22%3A%22Executive%22%2C%22createdOn%22%3A%7B%22date%22%3A%222021-02-17%2018%3A32%3A54.638030%22%2C%22timezone_type%22%3A3%2C%22timezone%22%3A%22America%5C%2FLos_Angeles%22%7D%2C%22expires%22%3A%7B%22date%22%3A%222021-02-17%2018%3A32%3A54.638030%22%2C%22timezone_type%22%3A3%2C%22timezone%22%3A%22America%5C%2FLos_Angeles%22%7D%2C%22token%22%3A%22%22%2C%22auth0%22%3A%22%22%7D

Then reading the cookie, extracting the json, and trying to compare the date "expires" to $today which is DateTime
Tried to convert the string date in the JSON back to an PHP DateTime object, so I can say is today > expires
I tried for hours, using getDate, strtotime, and reading up on time in seconds since the epoch.
If it ain't broke don't fix it
Discover my world at jkirkerx.com

QuestionMessage Closed Pin
14-Feb-21 10:11
ellaluceero14-Feb-21 10:11 
AnswerRe: How To create a table in MS Access contain more than 255 filed ? Pin
Richard Deeming14-Feb-21 22:05
mveRichard Deeming14-Feb-21 22:05 
QuestionBootstrap - How do I make an icon a href link Pin
Jim McElhiney10-Feb-21 15:33
Jim McElhiney10-Feb-21 15:33 
AnswerRe: Bootstrap - How do I make an icon a href link Pin
Peter_in_278012-Feb-21 13:58
professionalPeter_in_278012-Feb-21 13:58 
QuestionPHP V7.4.14, convert this database function, understanding mssql_fetch_field to sqlsrv_fetch Pin
jkirkerx10-Feb-21 9:36
professionaljkirkerx10-Feb-21 9:36 
AnswerRe: PHP V7.4.14, convert this database function, understanding mssql_fetch_field to sqlsrv_fetch Pin
jkirkerx12-Feb-21 13:14
professionaljkirkerx12-Feb-21 13:14 
Questionphp 7.4.14 convert smalldatetime to string for html display Pin
jkirkerx9-Feb-21 12:14
professionaljkirkerx9-Feb-21 12:14 
AnswerRe: php 7.4.14 convert smalldatetime to string for html display Pin
Richard Deeming9-Feb-21 22:00
mveRichard Deeming9-Feb-21 22:00 
GeneralRe: php 7.4.14 convert smalldatetime to string for html display Pin
jkirkerx10-Feb-21 5:19
professionaljkirkerx10-Feb-21 5:19 
GeneralRefresh a div with pjax Pin
Member 150664316-Feb-21 9:32
Member 150664316-Feb-21 9:32 
GeneralRe: Refresh a div with pjax Pin
OriginalGriff6-Feb-21 9:45
mveOriginalGriff6-Feb-21 9:45 
Question500 Error Pin
#realJSOP4-Feb-21 5:49
mve#realJSOP4-Feb-21 5:49 
AnswerRe: 500 Error Pin
Richard Deeming4-Feb-21 5:59
mveRichard Deeming4-Feb-21 5:59 
GeneralRe: 500 Error Pin
#realJSOP4-Feb-21 7:33
mve#realJSOP4-Feb-21 7:33 
GeneralRe: 500 Error Pin
Richard Deeming4-Feb-21 21:42
mveRichard Deeming4-Feb-21 21:42 
GeneralRe: 500 Error Pin
#realJSOP7-Feb-21 9:08
mve#realJSOP7-Feb-21 9:08 
QuestionVS code/Live Server Browser issue Pin
ISHYY4-Feb-21 4:42
ISHYY4-Feb-21 4:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.