我對Perl很陌生。我已經做了一個簡單的登錄腳本,應該在重定向到我的表單頁面之前設置cookie。我嘗試了所有我能想到的,但該cookie不會在Safari中設置。幾個帖子顯示輕微的變化,我已經嘗試了所有。Perl CGI :: Cookie未在Safari中設置
我的代碼:
my $userQuery = "SELECT user_name , password FROM egi_users WHERE user_name = '$username' AND password = '$cryptword'";
my $result = $dbh->prepare($userQuery);
$result->execute()or die "MYSQL ERROR : $DBI::errstr\n";
my $rows = $result->rows;
if($rows == 1){
#login is valid. Create cookie and send to patient_data page.
#print("success\n");
my $c = CGI::Cookie->new(-name=>'login_access',
-value=>$username,
-expires=>'+1h');
print $q->redirect(-uri=>'http://mytestserver.com/cgi/patient_data.pl' , -status => '301' , -cookie => $c);
}else{
print $q->redirect(-uri=>'http://mytestserver.com/);
}
我實現所有的東西似乎有必要來回CGI;
使用CGI; 使用CGI :: Carp ... 使用CG :: Session; 使用CGI :: Cookie;
腳本正確驗證並重定向,但沒有設置cookie。 我不知道我在做什麼。如果你有更好的方法建議, 這也很棒。
感謝您的期待
爲什麼要打印自己的頭文件而不是使用CGI模塊?爲什麼使用JavaScript重定向而不是HTTP重定向? – friedo
我試過使用http重定向,並且它們在打印完頭後似乎不起作用,所以如果在頁面中間需要重定向,我發現JS方法是唯一的選擇。就CGI打印標題而言,我第一次在昨天看到了這一點。 – Miek
HTTP重定向*是*標頭。 – friedo