#!/usr/bin/perl -w
#
#  PROGRAM:cookie-set.cgi
#
#  PURPOSE:Demonstrate how to SET a cookie through a Perl/CGI program
#uisng the CGI.pm module.
#
#  Copyright DevDaily Interactive, Inc., 1998. All Rights Reserved.
#

#------------------------------#
#  1. Create a new CGI object  #
#------------------------------#

use CGI;
$query = new CGI;

$from = $ENV{'HTTP_REFERER'};

#------------------------------------------------------------------------------#
#  2. Create the desired cookie using the cookie() method.
#     Do this before calling the header() method, because the cookie must be
#     incorporated into the HTTP header.
#
#  Note: Valid parameters for the cookie() call include:
#  -----------------------------------------------------
#
#-domaina partial or complete domain name for which the
#cookie is valid. Like '.devdaily.com'
#for the entire domain (www.devdaily.com,
#smtp.devdaily.com, etc.), or 'www.devdaily.com'
#to refer to one server.
#-expires(optional) The expiration date for this cookie.
#+60s60 seconds from now
#+20m20 minutes from now
#+5h5 hours from now
#+1d1 day from now
#-3d3 days ago
#nowimmediately
#+6M6 months from now
#+1y1 year from now
#Monday, 28-Dec-98 12:30:00 GMT
#expire at this specific date & time
#-namethe name of the cookie (req'd)
#-path(optional) If you specify this attribute, the 
#browser will check it against your script's URL
#before returning the cookie.
#The default is set to '/'.
#-secure(optional) The cookie will only be sent if the CGI
#request is occurring on a secure channel.
#-value(req'd) The value of your cookie. This can be a 
#scalar value, array reference, or hash
#reference.
#------------------------------------------------------------------------------#

# Get the input
#read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$buffer=$ENV{QUERY_STRING};
#print "Content-type: text/html\n\n";
#print $buffer;
#exit;

$skippy="no";

$_=$from;
$oldxf="google";
if (/$oldxf/i){
$skippy="yes";
}
if ($skippy eq "no"){
$cookie = $query->cookie(-name=>'GBAXfriend',
 -value=>$buffer,
 -expires=>'+45d',
 -path=>'/');


#--------------------------------------------------------------#
#  3. Create the HTTP header and print the doctype statement.  #
#--------------------------------------------------------------#

print $query->header(-cookie=>$cookie);


#--------------------------------------------------#
#  4. Give the page a title and a simple header.   #
#     (Not really needed in this simple example.)  #
#--------------------------------------------------#

#print $query->start_html('My cookie-set.cgi program');
#print $query->h3('The cookie has been set');


#-------------------------#
#  5. End the HTML page.  #
#-------------------------#
#skippy:
#print $query->end_html;
}




use LWP::Simple;
#print "Content-type: text/html\n\n"; 
#my $content = get("http://www.gbax.com/index.html");
#print $content;

if ($ENV{QUERY_STRING} eq ""){ 
my $content = get("http://openpandora.org/");
print $content;
}
else{
print "<meta http-equiv=refresh content=0;URL=http://openpandora.org/>";
}

#make sure affil account exists then update its details
#CAN'T DO THIS ON EDS SERVER
#$neededfile="affilfolks/$buffer";
#if (-e $neededfile)
#{ 
# 
#open (GUEST,"affilfolks/$buffer camefrom");
#@LINES=<GUEST>;
#close(GUEST);

#put the last 50 came from addresses into the users file
#open (GUEST,">affilfolks/$buffer camefrom");
#if ($skippy eq "yes"){ print GUEST "yes - ";}
#print GUEST "$from\n";
#for ($i=0;$i<50;$i++) {
#print GUEST $LINES[$i];
#}
#close(GUEST);
#exit;
#}

print "<br><Br>GP2X Loading...";
exit;