Google Answers Logo
View Question
 
Q: Need easy to use PHP Cookie Script ( No Answer,   7 Comments )
Question  
Subject: Need easy to use PHP Cookie Script
Category: Computers > Internet
Asked by: trimidium-ga
List Price: $10.50
Posted: 05 Mar 2005 16:15 PST
Expires: 04 Apr 2005 17:15 PDT
Question ID: 485356
I have a website (www.thesmartass.info) that has lots of iframes
inside of each other.  The purpose of this website is to be a
startpage to the internet.  Currently when you load the website you
see random images, random quotes, etc...

What I want is a basic cookie script that I can have multiple things defined in. 
(css, artwork, background, colors, navpage, centerpage, other)

How I would like it to work is via a get on the address line:
thesmartass.info?index.php?css=smartass5.css?Art=xevor-fallingspring.jpg?BG=somethingdark.jpg?Nav=sidebar.php

I need all the variables to be defined on the index page, but then i
need them all to work on all the subpages so that i can always set
them by referencing index.php

I want to also make sure that there is no set path for all the files
as It will be different for each variable. Also I need each variable
to have it's own default so that I can point it to a random script
until they choose to set a different cookie.

Does this make sense?  Go to: http://www.thesmartass.info/ and after
it loads hit refresh a couple times and you will see why I want it to
give people the ability to choose what is there the next time they
load the page.

Also if I could give people the ability to choose the default pages
that load in my iframes then it would cut the load time a lot as one
of the default loading pages loads a form with 400 playable nintendo
games in it now which is a bit slow.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Need easy to use PHP Cookie Script
From: eliteskillsdotcom-ga on 05 Mar 2005 16:25 PST
 
Just check out http://us2.php.net/manual/en/function.session-start.php


Search google "php cookies", "php session variables" add "tutorials"
keyword in separate search.


Plenty of free tutorials to go around.
Subject: Re: Need easy to use PHP Cookie Script
From: eliteskillsdotcom-ga on 05 Mar 2005 16:51 PST
 
Cool site too. I could never find the old beatle juice game. I have
weird memories of it as a kid.
Subject: Re: Need easy to use PHP Cookie Script
From: trimidium-ga on 05 Mar 2005 17:17 PST
 
I've already done that, I have been fighting to get multiple different
cookie scripts to do just what I ask and have not succeeded. 
Everytime I think I have created the perfect script, it doesn't even
set the cookie.  I think after so many wasted hours it is worth a few
dollars to have somebody else do it for me.  Thanks for the comment on
the website, I'm always trying to make it better... that's why I'm
here now ;)
Subject: Re: Need easy to use PHP Cookie Script
From: eliteskillsdotcom-ga on 06 Mar 2005 11:46 PST
 
Make sure you set session.auto_start=1 in your php.ini.

Also, if session.gc_divisor=session.gc_probability, it will not work.


Make sure you start with <? session_start(); ?> in all the pages you
CALL or create session variables in. It has to be the first thing on
your page.

Example
<? session_start(); ?>
Woked

lakdf<? session_start(); ?>
Nope sorry, data already output can't understand now. Stop everything.


Try adding ONLY
<?
session_start();
session_register('taco');
$_SESSION['taco'] = "lemmings";
?>

in one page and
<? session_start();
echo $_SESSION["taco"]." fall off cliffs. That's what ".$taco." do...";
?>

It uses two methods of grabbing the session var.
If that doesn't work there's probably something wrong with your php.ini.
Subject: Re: Need easy to use PHP Cookie Script
From: trimidium-ga on 06 Mar 2005 16:17 PST
 
i don't want sessions, i want cookies that will last for a year...
Subject: Re: Need easy to use PHP Cookie Script
From: eliteskillsdotcom-ga on 06 Mar 2005 16:36 PST
 
phpfreaks has an excellent working page by page tutorial:

http://www.phpfreaks.com/tutorials/120/1.php


I don't think I can simplify it much more than they can, but you've
probably already seen it just searching php cookies.
Subject: Re: Need easy to use PHP Cookie Script
From: trimidium-ga on 06 Mar 2005 23:17 PST
 
Fine you wanted me to do it myself so badly... well I have finally
fixed my cookie script, realizing it was only not working because I
was using a capitol letter to set the cookie and the script didn't
call for one.. grr, however I have another problem, I need this script
to be able to be loaded from index.php and understood from content
php... which currently doesn't work... here is my current script:

<?php 
 
if (!empty($setsidebar)) { 
 $sidebar = $setsidebar; 
 setSidebar(); 
} elseif (!empty($_COOKIE['sidebar'])) { 
 $sidebar = $_COOKIE['sidebar']; 
} elseif (!empty($eatcookie)) { 
 eatCookie(); 
} 
 
 
function setSidebar() { 
 global $sidebar; 
 setcookie('sidebar',$sidebar,time()+2678400,'/','thesmartass.info'); 
} 
 
function getSidebar() { 
 global $sidebar; 
  
 $default_sidebar = "sidebar2.php"; 
 
 if (!empty($sidebar)) { 
  $bobfile = $sidebar; 
  if (!file_exists($bobfile)) { 
   $bobfile = $default_sidebar; 
  } 
 } else { 
  $bobfile = $default_sidebar; 
 } 
  
 return $bobfile; 
} 
 
function eatCookie() { 
 setcookie('sidebar','',time()-2678400); 
} 
 
?> 

you can set this cookie by the following: 
http://www.thesmartass.info/content.php?setsidebar=sidebar1.php
http://www.thesmartass.info/content.php?setsidebar=sidebar3.php
http://www.thesmartass.info/content.php?setsidebar=eatcookie

but if you go to any of those pages you will notice my page is all
white and looks like crap, that's because content.php is just a
subpage of index

what I need is to be able to load the php script above on index.php
and having the variable still understood when i launch it on
content.php with getSidebar();  in theory my understanding is since i
defined the domain name in the setcookie line it should work for the
entire domain!?

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy