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
Solved

cookies and redirection

Posted on 2000-04-18
9
271 Views
Last Modified: 2013-12-25
I'm kind of new at cgi, and have a question about using cookies. I simply want to redirect the user to 1 of 2 URL's based on whether they have been to the site before. I know how to set a cookie, but i'm not sure how to use the cookie to determine if the user has already accessed the page. I assume some type of "if" "else" type code. Could someone email a script, or point me to where i could find example scripts. Ive looked a lot, but most sites show only how to create cookies. I'm using perl 5x.
Lisa.
0
Comment
Question by:wolverina
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 1

Expert Comment

by:hkmdj
ID: 2730129
0
 

Author Comment

by:wolverina
ID: 2733135
Thanx, however ive been there already... meow..!!!

Lisa.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 2740510
If you are not a member of the Perl-win32-web or Perl-win32-users mailing list, I suggest you join.  They have been active for over 4 years that I know of and are a HUGE pool of talent.  You can join here; http://www.activestate.com/support/mailing_lists.htm

While it doesn't answer your question, it will help your quest for a solution.

I do this very easily in .asp pages, the function is the same...;

<%
' Check for the cookie
Cookie = Request.Cookies("Wine")
%>
<% ElseIf Action="New" Then
            If Cookie = "" Then
Response.Redirect "nope.asp"
%>
      <% Else %>
            <!--#include file="nblank.inc"-->
            <% End If %>
<% End If %>
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:wolverina
ID: 2740867
Thanx, i appreciate the info. There's more code for javascript than perl, so i'm using that instead. I'm going to delete the question in a couple days. :)

Lisa.  
0
 
LVL 2

Accepted Solution

by:
chuckie79 earned 150 total points
ID: 2756571
Perl solution could be as follows

# Get Cookies using CGI.pm
# http://www.perl.com/CPAN-local/modules/by-module/CGI/CGI.pm-2.66.tar.gz
# http://www.perl.com/CPAN-local/modules/by-module/CGI/CGI.pm-2.66.readme
use CGI.pm

$test_cookie = cookie("firstvisit")
if ($text_cookie eq "yes")
{
  print "Location: http://www.something.com/secondvisit.html\n\n";
}
else
{
  print "Location: http://www.something.com/firstvisit.html\n\n";
}
0
 
LVL 2

Expert Comment

by:chuckie79
ID: 2756579
Sorry didn't read the original question very well. The above answer is for reading a cookie, have a look at the readme for CGI.pm. This module should cover most of what you probably would want to do.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 2756746
Why don't you just add a value to the cookie file that is created when the cookie is, like PageId=1, then if you check the cookie upon entering a page it is simply a matter of checking the pageId in the cookie and redirect if true.

You know you can always modify an existing cookie...

Take a look at the HTTP::Cookie.pm module in your Perl load.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 2756777
Why don't you just add a value to the cookie file that is created when the cookie is, like PageId=1, then if you check the cookie upon entering a page it is simply a matter of checking the pageId in the cookie and redirect if true.

You know you can always modify an existing cookie...

Take a look at the HTTP::Cookie.pm module in your Perl load.
0
 

Author Comment

by:wolverina
ID: 2757670
Thanx... ive figured it out in both perl and javascript now. Thanks again,
bye.

Lisa.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Fulfillment API php code sample 1 56
Wordpress plugins not working in html 3 37
One field not displaying content (ASP Classic) 8 29
Alert after MVC form submitted 1 22
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

792 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