Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Cookies and things...

by pmachin (Initiate)
on Feb 21, 2004 at 14:11 UTC ( [id://330798]=perlquestion: print w/replies, xml ) Need Help??

pmachin has asked for the wisdom of the Perl Monks concerning the following question:

Greetings everyone! I'm a newbie to Perl, hopefully some of you more experienced programmers can help me out.

I have 3 questions:

1: I have the following code creating a cookie:

use CGI; $query = new CGI; my $cookie = $query->cookie(-name=>'cookie', -value=>'hello', -domain= +>'www.cis$ print $query->header(-cookie=>$cookie);

this scrpt (login.cgi)is in the cgi-bin directory, I forward this script to home.cgi in the same cgi-bin directory and works fine when it accesses the cookie in home.cgi, however, when I put home.cgi one directory above cgi-bin, the cookie is not accessed.

The following is the cookie retrieving code in home.cgi:

#print "Content-type: text/html\n\n"; $query = new CGI; $cookie = $query->cookie('cookie'); print $query->header(); if ($cookie) { #print "Content-type: text/html\n\n"; $query = new CGI; $cookie = $query->cookie('cookie'); print $query->header(); if ($cookie) { print "done"; } else { print "naughty boy!" #print "#print "<META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://myadd +ressgoeshere.com/cgi-bin/login.cgi">"; }

why is done printed if I put the cookie in the same directory, but naughty boy is printed if I put it in another directory> I tried changing the other parameters in cookie creation to make the cookie accessible in the whole domain of my website, but for some reason this is not working!

2: Another thing, the meta tag that I have commented out, does not work even when the elseif is taken, is there anything wrong with the tag, is global accessing like that alright?

3: Lastly, I am writting my html files with dreamweaver, however, if I want to read them in again, all this extra code that checks for the cookie and so forth prevents me from seeing anything but the code view in dreamweaver, does perl have any way to redirect to a file within a secure directory. This would solve two problems

  1. I won't have to check for cookies at all
  2. I would redirect to a complete html file (not mixed with cgi) so that I could edit it with dreamweaver.

If this is not possible, how do you redirect to an unsecure file (without the html meta tag).

Thanks a bunch.

Edited by Chady -- added formatting tags.

Replies are listed 'Best First'.
Re: Cookies and things...
by benn (Vicar) on Feb 21, 2004 at 15:42 UTC
    as for 2 & 3...

    2. You're printing a quote-delimited string that itself contains quotes...you could either change the quotes in your string to single ones, like this...
    print "<META HTTP-EQUIV='Refresh' CONTENT='whatever'>"
    or escape the double quotes thus...
    print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"etc.">";
    or change the delimiters...
    print '<META HTTP-EQUIV="Refresh" CONTENT="etc.">';
    or use a "HEREDOC"...
    print << "HERE"; <META HTTP-EQUIV="Refresh" CONTENT="stuff"> HERE
    3. You could either read in a "straight" html file and print it back out again, or check out one of the templating modules such as HTML::Template. Both methods would allow you to play with your HTML layout in dreamweaver (although personally, I prefer / would recommend writing HTML simply in a text editor).

    Cheers,
    Ben.
Re: Cookies and things...
by The Mad Hatter (Priest) on Feb 21, 2004 at 14:14 UTC
    I'd set the right path using the -path key when creating the cookie to be sure it is being set to the right value. See the doc for how to do so.

    In any case, it sounds like your problems could be more than solved by using HTTP's Basic auth for securing the directory you wish.

    Update I'll assume that my $cookie = $query->cookie(-name=>'cookie', -value=>'hello', -domain=>'www.cis$ isn't the actual line in use, otherwise I would not expect it to work at all.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://330798]
Approved by Chady
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-19 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found