cookie error

Started on the old forum in May 2009 · view the original in the archive · old links redirect here

12 replies · 816 views · started 17 years ago · 1 min read

3 participants
ori Lead · 512 posts #1

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
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
something else Fellow · 2,296 posts #2

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

ori Lead · 512 posts #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

something else Fellow · 2,296 posts #4

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

ori Lead · 512 posts #5

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

syrus Junior · 44 posts #6

ori wrote: 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
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.

ori Lead · 512 posts #7

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

something else Fellow · 2,296 posts #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*

ori Lead · 512 posts #9

thats not practical lol seems only ie8 is doing it

something else Fellow · 2,296 posts #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

ori Lead · 512 posts #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

ori Lead · 512 posts #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()

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")

ori Lead · 512 posts #13

alternativly u can use time()+606024 which is 1day but strtotime("+1 day") is easier

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close