From: Alex T. K. <ale...@ya...> - 2003-10-15 09:56:59
|
Hi All-- I've written a patch that lets PHP iCalendar display iCalendars that require 401 authentication. This catches a 401 authentication error and pops the user/pass dialog before exiting to the error page. Basically, I'm catching the warning message that is output to the screen and checking it since the fopen function doesn't give us anything useful (that I could find) in the built in error handling. More on this in my blog: http://www.alexking.org/blog/index.php?p=520 Here is the code I added to ical_parser.php, line 69: // patch to allow 401 authentication for iCalendars ob_start(); $ifile = fopen($filename, "r"); $err_msg = ob_get_contents(); ob_end_clean(); if ($ifile == false && strstr($err_msg, "HTTP/1.1 401 Authorization Required")) { function prompt_401() { header('WWW-Authenticate: Basic realm="PHP iCalendar"'); header('HTTP/1.0 401 Unauthorized'); echo 'This iCalendar requires a username/password.'; die(); } if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { prompt_401(); } else { if (strstr($filename, "http://")) { $filename = 'http://'.$_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW'].'@'.substr($filename, 7); } else if (strstr($filename, "webcal://")) { $filename = 'webcal://'.$_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW'].'@'.substr($filename, 9); } ob_start(); $ifile = fopen($filename, "r"); $err_msg = ob_get_contents(); ob_end_clean(); if ($ifile == false && strstr($err_msg, "HTTP/1.1 401 Authorization Required")) { prompt_401(); } } } // /patch I haven't dug into the PHP iCalendar code very deeply, so this may break something somewhere that I don't know about. Comments, corrections and feedback are welcome. --Alex __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com |