Jump to content

[SOLVED] Setting and getting cookies?


ahvceo

Recommended Posts

Hi All,

 

I am 72 and just trying to learn php, it wasn't around when I was programming 20 years ago.  I got this code off of the web and I don't quite understand what is happening!  I do know that the $_GET statement returns the reefer's username from the affiliate link but that is about all.

 


if($_GET['ref']) 
{		
  if($cookieExpiration != 0)
    $cookieLifetime = time() + $cookieExpiration*86400;
  else
    $cookieLifetime =  time() + 3650*86400;
    
  SetCookie ("ref",$_GET['ref'], $cookieLifetime, $cookiePath, $cookieDomain);
  SetCookie ("ref",$_GET['ref'], $cookieLifetime, $cookiePath, $cookieDomain);
  SetCookie ("ref",$_GET['ref'], $cookieLifetime, $cookiePath, $cookieDomain);
  SetCookie ("ref",$_GET['ref'], $cookieLifetime, $cookiePath, $cookieDomain);
  SetCookie ("ref",$_GET['ref'], $cookieLifetime, $cookiePath, $cookieDomain);

 

as you can see there are 4 Set "SetCookie" statements in a row that look identical to me.  Is there a difference in what each statement does?

 

In a different php file I want to use the following code...

 


$myFile = 'testFile.txt';
$fh = fopen($myFile, 'a') or die("can't open file");

$ref = $HTTP_COOKIE_VARS["ref"];
while (list (WHAT GOES HERE, AND HERE, AND HERE)=each ($HTTP_COOKIE_VARS))
fwrite($fh, "WHAT GOES HERE");
fclose($fh)

 

to read the cookie I just set with the previous statements and write them out to a file so I can see what is returned.

 

Is "$HTTP_COOKIE_VARS" a good statement?  I read some where that it was depreciated and replaced with a new statement.

 

Since I don't know what or how many variables are being returned what goes where I have written "WHAT GOES HERE", AND HERE, AND HERE" in the code above? There were 2 variables in the list or orginally.

 

Thanks

ahvceo

 

PS What is wrong with this text editor?  I cannot see the bottom of the page after a few lines.  Why doesn't someone fix it?

 

Link to comment
https://forums.phpfreaks.com/topic/158714-solved-setting-and-getting-cookies/
Share on other sites

//set a cookie
setcookie("name","Wayne");

//get said cookie
$name = $_COOKIE['name'];

//print $name
echo $name; //Will be Wayne

 

You're right. $HTTP_COOKIE_VARS is pretty outdated.

 

$HTTP_COOKIE_VARS is now $_COOKIE

$HTTP_POST_VARS is now $_POST

$HTTP_GET_VARS is now $_GET

They look look identical to me as well so will all do the same thing..

 

well technically if you used all of them then only the first one will create a cookie if it doesn't exist, the rest would update it ;)..

but if only one of those existed it wouldn't matter which one

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.