Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Session Information

Posted on 1998-12-17
2
Medium Priority
?
160 Views
Last Modified: 2013-12-25
How do i send some information across pages in a session in CGI? i want the information to be persistent in a user session.
0
Comment
Question by:britto_nl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
flivauda earned 210 total points
ID: 1830175
You have two options you can set a cookie or you can pass it around through the query string. I would set a  cookie.
==================
# Here is how you would set the cookies
&setMemberCookie($username);    # expires in one day
&setMemberCookie($username, 1); # expires in one year

# Here is how you would read the cookies
&getMemberCookie(*COOKIE);


sub setMemberCookie
{ local ( $username, $permanentcookieflag) = @_;

  $cookie = uname=$username&otherinfo=$otherinfo;
  $expiration = &getCookieTimestamp($permanentcookieflag);
  print "Set-Cookie: login=$cookie; expires=$expiration; path=/; domain=.yourdomain.com;\n";
  $ENV{'HTTP_COOKIE'} = "login=$cookie; $ENV{'HTTP_COOKIE'}";
}


# getCookieTimestamp
#
# returns a timestring in the format:
# Weekday, DD Month YEAR HH:MM:SS GMT
#
# if the call to setMemberCookie contains a permanentcookie
# flag that is true, then the cookie will expire in one year.
# otherwise the cookie will expire in one day.
#
#############################################################

sub getCookieTimestamp{
    local ( $permanentcookieflag) = @_;
    local ($months, $weekdays, $ampm, $time_string, $cookietimeout);

    if ( $permanentcookieflag )
      { $cookietimeout = 60 * 60 * 24 * 365;
      }
    else
      { $cookietimeout = 60 * 60 * 24;
      }

    local ($sec, $min, $hour, $day, $nmonth, $year, $wday, $yday, $isdst) = gmtime(time+$cookietimeout);

    $months = "Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec";
    $weekdays = "Sun/Mon/Tue/Wed/Thu/Fri/Sat";

    if ($hour > 12) { $hour -= 12; $ampm = "pm"; }
    else { $ampm = "am"; }

    if ($hour == 0) { $hour = 12; }
    $year += 1900;
    $week  = (split("/", $weekdays))[$wday];
    $month = (split("/", $months))[$nmonth];

    $time_string = sprintf("%s, %s %s %s %02d:%02d:%02d GMT", $week, $day, $month, $year, $hour, $min, $sec);
    return $time_string;
}



# getMemberCookie
#
# if the login=blablabla cookie is set, decode it and return
# the pointer to the hash.  otherwise return false.
#
#############################################################

sub getMemberCookie
{ local (*COOKIE_DATA) = @_;
  local ( $cookie_string, @key_value_pairs, $key_value, $key, $value);

  if ( $ENV{'HTTP_COOKIE'} =~ /login=([^;]+)/ )
  {
  }
  else
  {
    return("false");
  }

  @key_value_pairs = split (/&/, $cookie_string);
  foreach $key_value (@key_value_pairs)
    { ($key, $value) = split (/=/, $key_value);
      $value =~ tr/+/ /;
      $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;

      if (defined($COOKIE_DATA{$key}))
        { $COOKIE_DATA{$key} = join ("\0", $COOKIE_DATA{$key}, $value);
        }
      else
        { $COOKIE_DATA{$key} = $value;
        }
    }

   return %COOKIE_DATA;
}


0
 

Author Comment

by:britto_nl
ID: 1830176
Adjusted points to 75
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question