Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^5: Cookie and Session

by Anonymous Monk
on Nov 04, 2011 at 02:31 UTC ( #935819=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Cookie and Session
in thread Cookie and Session

@parameters = split(/&/,$request);

CGI, which you're already using CGI, does that for you, and does it correctly, so you should actually use it :)

Please don't copy/paste that read(STDIN, $request,$ENV{'CONTENT_LENGTH'}); anymore

Read use CGI or die;, especially Ovids CGI Course, CGI Programming 101.

Read CGI Help Guide and Troubleshooting Perl CGI scripts

Read this if you want to cut your development time in half!

While you're already doing all this reading, might as well read the CGI documentation and the examples, those that come with CGI, and some others, like Re: Help!! Premature ending of script headers?, Re^3: Trying to get an RSS to display.

Once you get past simple programs like this

#!/usr/bin/perl -- use strict; use warnings; use CGI (); use Data::Dumper (); #zum debuggen Main( @ARGV ); exit( 0 ); sub Main { return DebugCGI(); } sub DebugCGI { binmode STDOUT, ":encoding(utf8)"; my $cgi = CGI->new; $cgi->charset('UTF-8'); # Content-Type: text/html; charset=UTF-8 # <meta http-equiv="Content-Type" content="text/html; charset=utf-8" / +> $cgi->cookie; # "fetch" cookies print $cgi->header(); # Write HTTP header print $cgi->start_html, $cgi->b( rand time, ' ', scalar gmtime ), '<table border="1" width="%100">', '<tr><td>', $cgi->Dump, '</td>', '<td><div style="white-space: pre-wrap; overflow: scroll;">', $cgi->escapeHTML( DD($cgi) ), '</div></td></tr>', '<tr><td>', $cgi->escapeHTML( 'CGI::Cookie->fetch' ), '</td>', '<td><div style="white-space: pre-wrap; overflow: scroll;">', $cgi->escapeHTML( DD( { CGI::Cookie->fetch } ) ), '</div></td></tr>', '</table>', '<h1>And now %ENV</h1>', CGI->new( \%ENV )->Dump, $cgi->end_html; } sub DD { scalar Data::Dumper->new( \@_ )->Indent(1)->Useqq(1)->Dump; } __END__

CGI::Application/http://cgi-app.org/ can help you organize your program , as could mojo / dancer / catalyst


Comment on Re^5: Cookie and Session
Select or Download Code
Re^6: Cookie and Session
by devarishi (Initiate) on Nov 04, 2011 at 05:23 UTC
    Sir, Your codes give this output:
    Content-Type: text/html; charset=UTF-8 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <b>861183026.613647 Fri Nov 4 05:18:53 2011</b><table border="1" wi +dth="%100"><tr><td><ul></ul></td><td><div style="white-space: pre-wra +p; overflow: scroll;">$VAR1 = bless( { &quot;.parameters&quot; =&gt; [], &quot;use_tempfile&quot; =&gt; 1, &quot;.etab&quot; =&gt; 1, &quot;.charset&quot; =&gt; &quot;UTF-8&quot;, &quot;.elid&quot; =&gt; 1, &quot;.fieldnames&quot; =&gt; {}, &quot;.cookies&quot; =&gt; undef, &quot;param&quot; =&gt; {}, &quot;escape&quot; =&gt; 1, &quot;.header_printed&quot; =&gt; 1 }, 'CGI' ); </div></td></tr><tr><td>CGI::Cookie-&gt;fetch</td><td><div style="whit +e-space: pre-wrap; overflow: scroll;">$VAR1 = {}; </div></td></tr></table><h1>And now %ENV</h1><ul> <li><strong>USERPROFILE</strong></li> <ul> <li>C:\Documents and Settings\Default User</li> </ul> <li><strong>PSMODULEPATH</strong></li> <ul> <li>C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\</li> ... Output Truncated Here... ... <li><strong>TMP</strong></li> <ul> <li>C:\WINDOWS\TEMP</li> </ul> </ul> </body> </html>

    Is working with Cookies/CGI in Perl that much difficult a task?

      Sir, Your codes give this output:

      Why do you think I would need to see it?

      Is working with Cookies/CGI in Perl that much difficult a task?

      Not if you have a basic understanding of the internet/computer programs

      If you copied his script and you're seeing all that in your browser, then go back to what I said above: your server is sending headers ahead of what your CGI scripts are sending (and apparently encoding your output as well). You'll have to fix that before your CGIs can work at all. Your web server shouldn't send any headers when it runs a CGI; it should let the CGI take care of that.

      Try this extremely simple CGI script. If you see anything in your browser other than "Hello, world!", you have a server problem. You should NOT see the Content-type line.

      #!/usr/bin/perl use warnings; use strict; print "Content-type: text/html\n\n"; print "Hello, world!";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935819]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2014-07-13 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (249 votes), past polls