Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MISBEHAVING IF STATEMENT

Status
Not open for further replies.

madaxe2

Technical User
Jan 23, 2005
43
US
WHY DOES MY IF STATEMENT NOT WORK
Code:
#!/Perl/bin/perl -wT

use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;


print "Content-type: text/html\n\n";

my $query = new CGI;
my $cookieinfo = $query->cookie('mcjeeves.net');

if (!$cookieinfo)

{
 
print <<"EOF";
<META http-equiv="refresh" content="0;URL=http://www.yahoo.com">;
EOF

exit;

}

else

{

print <<"EOF";
<META http-equiv="refresh" content="0;URL=http://www.lycos.com">;
EOF

}
 
try this,

Code:
my $cookieinfo = $query->cookie('mcjeeves.net');
print "[$cookieinfo]\n";
if ($cookieinfo ne "" ) {

HTH
--Paul


cigless ...
 
What do you mean it "Does Not Work"?

Is it doing the opposite?
Is it doing only one option no matter what?
Is it giving a script error?

Just some ideas:
What code are you using to create the cookie? Here is some to check yours:
Code:
#setup the cookie
my $cookie_out = $query->cookie(-name=>'cookiename',-value=>"$name;$email;$anothervalue",-expires=>'+3h',-path=>'/',-domain=>'.somedomain.com',-secure=>0); 

#write the cookie
print $query->header(-cookie=>$cookie_out); 

#Get the cookie
my $cookie_in = $query->cookie('cookiename'); 

#Split all vales into an array (cookie values are seperated by ";", so if you split at ";" you get an array of values in the same order that you entered them
@allcookies = split(/;/,$cookie_in);

if(!$allcookies[1])
 {
 print "There is no cookie";
 }
else
 {
 print "Cookie found";
 }

I am guessing you do not need to split your cookies for this process, but it may help you when you do need to get all the values. Please explain a little more on what does not work.
 
It was just hitting the first half of the if statement and going to the first url no matter what


Madaxe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top