Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

cookie encoding

by me01273 (Initiate)
on Apr 22, 2006 at 20:19 UTC ( [id://545081]=perlquestion: print w/replies, xml ) Need Help??

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

I need some help with my script. i have the code below, which i think will do what i want it to. How can i make it into an actual working page? At the moment it just gives me "internal server error" I basicly have a program that sets a cookie using the pm_encode function. i am trying to make a page that will grab the cookie decode it using pm_decode and place the cookie back with a different name. Any help is greatly apreciated. David
#!/usr/bin/perl ############################### # find the root if this is IIS: ############################### if($ENV{'SERVER_SOFTWARE'} =~ m/IIS/) { if($root eq "" && $ENV{'PATH_TRANSLATED'} ne "") { my $pt = $ENV{'PATH_TRANSLATED'}; my @pts = split(/\\/, $pt); $pts[-1] = ""; $root = join "/", @pts; $OS = "NT"; } } my $lp = $req->cookie("pmpre"); my ($clogin, $cID) = split(/\|/, pm_decode($lp)); my $cookie_pmpre_login = $req->cookie( -NAME => "username", -VALUE => "$clogin", -EXPIRES => "+1y", -PATH => "/" ); print $req->header(-COOKIE => $cookie_pmpre_login); exit;

Replies are listed 'Best First'.
Re: cookie encoding
by tempest (Sexton) on Apr 22, 2006 at 21:01 UTC
    which internal server error? Check your web logs.

    It is possible that you didnt CHMOD properly on the server.

      Failure to chmod +x will usually result in 403 Forbidden. Internal Server Error is more likely to mean that the script didn't print valid HTTP headers followed by a newline before anything else on standard output. This can be due to the author just forgetting to do that, or it can be due to a logic flaw, syntax error, or other issue. (update: it can also be due to omitting the Content-type header, which is mandatory, at least under apache.) Whatever it is, it definitely means you should look in the error log. I usually tail -f the error log, hit enter a couple of times, and then hit reload in the browser. If the site isn't too high-traffic, this makes it easy to see exactly which errors were coming from the script in question.


      Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.
Re: cookie encoding
by pingo (Hermit) on Apr 23, 2006 at 08:55 UTC
    Generally speaking, one way of finding problems with CGI's is to run them from the prompt and see what they say (especially useful if you add warnings: #!/usr/bin/perl -w). If you need %ENV variables you can add them with something like "export SERVER_SOFTWARE=IIS" (if you use bash) before running the script.
Re: cookie encoding
by Anonymous Monk on Apr 22, 2006 at 20:52 UTC
Re: cookie encoding
by jonadab (Parson) on Apr 23, 2006 at 12:03 UTC

    I don't see where $req is assigned, but you try to call one of its methods. You can't call a method on undef, so unless I'm missing something, your code as it stands isn't viable. Chances are the server's error log will also tell you the same thing.


    Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.

Log In?
Username:
Password:

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

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

    No recent polls found