cookie error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    cookie error

    ive been making a code 2 use cookies for my mobile script i put in a code 2 give a error if cookie cant be stored for older mobiles or ppl that turn cookies off but ppl are getting the error then when they reload it comes up wif the site any suggestions 2 fix this

    the code im using is

    PHP Code:
    <?php
    define
    ('DRK',true);
    putenv("TZ=Australia/Sydney");
    session_name("session_id");
    session_start();
    $act get_var("act");
    $mode get_var("mode");
    if (
    $act == "index") unset($_SESSION['uid']);
    if (!isset(
    $_SESSION['username'])) $_SESSION['username'] = "Guest";
    if (!isset(
    $_SESSION['ses'])) $_SESSION['ses'] = "Guest_".substr(md5(time()),0,12);
    if (empty(
    $act)) header("Location: http://$_SERVER[SERVER_NAME]/?act=index");
    if (!isset(
    $_COOKIE['session_id'])) die("You must enable cookies to use this site"); // this is where the problem lies

    #2
    debug it:
    print_r($_COOKIE);
    may need to use:
    setcookie("session_id","test");

    Comment


      #3
      i think its when ppl type site.com/?act=index if they type jus site.com then they dnt get the no cookie error

      Comment


        #4
        you could try using mod rewite to prevent the act=index

        Comment


          #5
          ive made the site so it always uses act=index lol the glitch is jus its showing the error when cookie is stored

          Comment


            #6
            Originally posted by ori View Post
            ive been making a code 2 use cookies for my mobile script i put in a code 2 give a error if cookie cant be stored for older mobiles or ppl that turn cookies off but ppl are getting the error then when they reload it comes up wif the site any suggestions 2 fix this

            the code im using is

            PHP Code:
            <?php
            if (!isset($_COOKIE['session_id'])) die("You must enable cookies to use this site"); // this is where the problem lies
            its pretty straight forward, the first time this script is called the line above will set the cookie and also echo that message. The next time u reload or visit the page it wnt show up because it was set previously.

            Comment


              #7
              i no... its obvious whats happening but how 2 have the msg only when cookie cant be stored

              Comment


                #8
                in that case cant you use a second page to set the cookie with a header redirecting to current page? ........ i use this way to stop people from people pushing back and reposting ..... so i dont have to restrict caching of pages making load time quicker*

                Comment


                  #9
                  thats not practical lol seems only ie8 is doing it

                  Comment


                    #10
                    guess its not practical for that but it would solve your problem
                    i guess the only real use for it is to stop flooders lol
                    maybe you will have to change your links for ie8

                    Comment


                      #11
                      i havnt tested the other ie versions few other forums had problems relating to ie7 and up even a few on firefox am gonna try something different wif my guest sessions

                      Comment


                        #12
                        i found a solution seems when sessions expire after the 30min period there classed as expired meaning there no longer isset so i made this function you's can run it thru addonline()

                        PHP Code:
                        function UpdateCookie()
                        {
                        if (isset(
                        $_COOKIE['session_id'])) setcookie("session_id",$_COOKIE['session_id'],strtotime("+1 year"),"/");

                        to change the expire time jus edit strtotime("+1 year")

                        Comment


                          #13
                          alternativly u can use time()+60*60*24 which is 1day but strtotime("+1 day") is easier

                          Comment

                          Working...
                          X