+ -
当前位置:首页 → 问答吧 → 请教个Perl CGI保存session问题

请教个Perl CGI保存session问题

时间:2010-08-16

来源:互联网

  1. #!/usr/bin/perl -w
  2. use CGI qw(:standard);
  3. use CGI::Session;
  4. #print "Content-Type:text/html\n\n";
  5. my $cgi = new CGI;

  6. #my $q = new CGI;
  7. my $method = request_method();
  8. my $User   =$cgi->param("USER");
  9. my $Passwd = $cgi->param("PASSWD");

  10. if ( $User eq 'david' && $Passwd eq '110110' ) {
  11.     my $session =
  12.       new CGI::Session( "driver:File", $cgi, { Directory => '/tmp' } );

  13.     my $cookie = $cgi->cookie( CGISESSID => $session->id );

  14.     print $cgi->header( -cookie => $cookie );

  15.     $session->param( 'f_name', 'httpsession' );
  16.     print "<script>";
  17.     print "window.location.href='2.pl\'";
  18.     print "<\/script>";
  19. }
  20. else {
  21.     print "login error<br>";
  22. }
复制代码


我在这个cgi前端写了个静态页面,通过当前这个cgi来获取前端的表单用户名密码 ,为什么当不启用print "Content-Type:text/html\n\n";在web中不能访问,
我启用print "Content-Type:text/html\n\n";的时候又不能保存session,但是web能访问, 望高手们帮忙看下

作者: mitmax   发布时间: 2010-08-16

session应该在所有输出前面~~~~

作者: 黑色阳光_cu   发布时间: 2010-08-16

CGI::Session模块有个header方法。
不能直接使用print "Content-Type:text/html\n\n"。

作者: 兰花仙子   发布时间: 2010-08-16



QUOTE:
CGI::Session模块有个header方法。
不能直接使用print "Content-Type:text/html\n\n"。
兰花仙子 发表于 2010-08-16 17:55




    能写出来下吗

作者: mitmax   发布时间: 2010-08-16



QUOTE:
能写出来下吗
mitmax 发表于 2010-08-16 17:56




    print $session->header();

作者: 兰花仙子   发布时间: 2010-08-16