Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Perl Monk, Perl Meditation
 
PerlMonks  

cgi page not showing

by jeff280679 (Initiate)
on Jul 01, 2002 at 06:55 UTC ( #178479=perlquestion: print w/ replies, xml ) Need Help??
jeff280679 has asked for the wisdom of the Perl Monks concerning the following question:

I am having problems with a script which uses a module i have also written for authentication and user information. The code section with the problem is:
my $cgi = new CGI; print $cgi->header(); # get the User, or go to login page my $user = new GWAK::User() or GWAK::User->redirect_to_login(GWAK::User->errstr); print $user->page_start();
which currently gives me a blank page in ie with default looking source, which is not written by me:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> +</HEAD> <BODY></BODY></HTML>
if I change the code at the top to:
my $cgi = new CGI; print $cgi->header(); # get the User, or go to login page my $user = new GWAK::User() or die "Invalid User"; print $user->page_start();
The page prints completely correctly (ie. does not die either). The function replaced, GWAK::User->redirect_to_login only prints a redirect message and returns, why would this stop the page from displaying?

Comment on cgi page not showing
Select or Download Code
Re: cgi page not showing
by caedes (Pilgrim) on Jul 01, 2002 at 07:03 UTC
    The only way you will get the default HTML document in IE is if your script sends the http headers and nothing else. Therefore, in the first example, the $user->page_start(); is not getting sent to the browser as the document source. Try using an http agent that will allow you to view the raw headers. eg. cURL

    -caedes

Re: cgi page not showing
by little (Curate) on Jul 01, 2002 at 07:24 UTC
    # get the User, or go to login page my $user = new GWAK::User() or GWAK::User->redirect_to_login(GWAK::User->errstr);
    seems to contain your problem. So what are you really trying to attempt here? check if the user exists? if the user is valid? logged in? Well, if thats fine, but if not, how could there be an User object that supports this method?

    Have a nice day
    All decision is left to your taste

    Update

    While your code is not a production release you might want to add the line
    use CGI::Carp qw(fatalsToBrowser);
    which would bring errors occuring due to the usage of warnings and strict (you do use those, don't you?) directly to your browser. Using diagnostics might give even more detailed reasons if an error occures :-)

      I do have use CGI::Carp qw(fatalsToBrowser) and am using strict (of course:). But I get nothing.

      What *should* happen is the when a new GWAK::User is created it authenticates using cookies, then fills a hash with user data and returns the reference. If it fails (bad auth, cannot access database..) it should call GWAK::User->redirect_to_login which is a class method which should just print a page which redirects to the login page.

      The thing is, the call to new GWAK::User doesn't fail (it works if I remove the GWAK::User->redirect_to_login) but all that is sent to the browser is the HTTP headers. No error messages anywhere. It's like having the GWAK::User->redirect_to_login creates a black hole that the script does not come out of.

        Well, as I said, you cannot call an object method if the object does not exist and its values aren't set, so simply try this instead :-)
        my $cgi = new CGI; # get the User my $user = new GWAK::User(); # did it work ? if (!$user) { # if not go to login page print $cgi->redirect("insert your login_url"); } else { # or proceed print $cgi->header(); ... }
        caedes is right, since you once write a header you cannot write a second one, but in my experience a mistakenly written second header would then just occur as plain text, but that might differ depending on the default mime-type setting of the webserver.

        Have a nice day
        All decision is left to your taste
Re: cgi page not showing
by uwevoelker (Pilgrim) on Jul 01, 2002 at 08:45 UTC
    Hello,
    look in your error_log - there might be a problem with your program.
    cd /var/log/httpd tail error_log
    But check the right path first.
      No i get nothing in the error log - that's my problem:) I did have use CGI::Carp qw(fatalsToBrowser); but I removed it to make sure it wasn't a problem, but still I get nothing in the error log.
        So you might wanna post some more code?
        Have a nice day
        All decision is left to your taste
        What browser are you using? Have you turned the caching off?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2014-04-16 16:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (433 votes), past polls