Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

Oh GOD...he's back again, this time playing with cookies....
Welcome, Guest. Please login or register.
November 21, 2008, 01:01:20 PM
11306 Posts in 1249 Topics by 501 Members
Latest Member: rosaline
Experts Round Table Network  |  Serverside Technology  |  PHP  |  Oh GOD...he's back again, this time playing with cookies.... « previous next »
Pages: [1]
Author Topic: Oh GOD...he's back again, this time playing with cookies....  (Read 264 times)
DougB

Offline Offline

Posts: 16


« on: March 02, 2007, 01:01:20 PM »

Greetings gang,
Well here I go again looking for help...Since I finished beating the last problem into submission with the help of rdivilbiss, VGR...(Thanks Guys!) I've been trying to set a cookie named 'MDIA' from a file with the function of having it live for two weeks using this code...

Code:
<?php
  session_start();

  $cookies = False;   

  setcookie('MDIA', $_POST['MDIA'], time()+60*60*24*14);
   ?>
   
<?php

ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset($_SESSION["Validated"]) && ($_SESSION["Validated"] == 1))
   {
?>

<?PHP
require ('includes/header.html');
?>
html page info...yada yada yada...

and this is the retrieval code from the other page where I wanted to pick up the code from

Code:
<?php

error_reporting (E_ALL & ~E_NOTICE);
ini_set ('display_errors', 1);

 
if (isset ($_COOKIE['MDIA']))
   {
    print "Welcome back, thank you for shopping at ACME Widgets";
    }

if (isset($_POST['Submit']))  //Post handling method
{
$error = 0; $errorlist = ''; 

At this point I'm not seeing the script I want printed
Quote
print "Welcome back, thank you for shopping at ACME Widgets"
on the page...can anyone point out what I've done wrong here.

Thanks in advance guys...

DougB
learning more daily....
Logged

More coffee....
rdivilbiss
Governing Council Member
*
Offline Offline

Posts: 414



WWW
« Reply #1 on: March 02, 2007, 01:17:38 PM »

Code
Language: php (GeSHi-highlighted)
setcookie('MDIA', $_POST['MDIA'], time()+60*60*24*14);

What if $_POST['MDIA'] is empty or not set?  (Just Guessing)

maybe

Code
Language: php (GeSHi-highlighted)
if ((isset($_POST['MDIA']))&&($_POST['MDIA']!='')) {
    setcookie('MDIA', $_POST['MDIA'], time()+60*60*24*14);
}
« Last Edit: March 02, 2007, 01:30:32 PM by rdivilbiss » Logged

Rod
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #2 on: March 02, 2007, 05:03:20 PM »

absolutely. I don't see why you use $_POST['MDIA']

Usually, people know the content of the cookie they will send to the client's browser (it may be refused silently, too - check your browser's settings! It should at least be on "ask every time" if not "accept all cookies" (not recommended) -

your setcookie() call uses usually the cookie's name ('MDIA' in your case) then the contents urlencoded (IMHO) - I suggest to store the currently logged in pseudo or proveded name - then the expiration time as demonstrated by the code you use

unless you show me the form having the name='MDIA' field, I can't tell more
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
DougB

Offline Offline

Posts: 16


« Reply #3 on: March 02, 2007, 08:51:46 PM »

We're using Larry Ullman's book "PHP For the World Wide Web" as the text for this course learning php. The $_POST['MDIA'] was a name I came up with for the assignment based on what was used as an example in the book. It has no reference to anything in any of the files other than as a name for the cookie only. I spent quite a bit of time today as well at www.php.net/manual/en but didn't come up with anything other than what I came up with so far...What would you two suggest I do, the cookie doesn't have to be anything special, its only for demonstration purposes...Thanks guys...ad security isn't an issue once again although I better get used to adding some type of filter quickly for real life examples...

DougB
Logged

More coffee....
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #4 on: March 03, 2007, 06:08:11 AM »

I suggest you give a lecture to this :

http://www.europeanexperts.org/question/TOUTES/ZONES/1446.html

and

http://www.europeanexperts.org/question/Web/G%E9n%E9ralit%E9s/1462.html
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
Pages: [1]
« previous next »
    Jump to: