[thelist] send HTTP authentication from PHP page?
Greg Holmes
greg.holmes at gmail.com
Thu Oct 7 08:56:31 CDT 2004
Jason Handby wrote:
>>You could put the PDFs in a directory outside of the web root. And then you
>>could create an ASPX page (say) that opened the relevant PDF file and
>>streamed it to the client after sending the appropriate mime type header. I
>>think this would work...?
And then Noah St.Amand wrote:
>I hadn't thought of that -- you're right, it should work.
>
>One day I'll get around to trying it . . .
Here's my aspx code that's worked OK with IE on NT
and XP. I found the relevant info to develop it on a
website somewhere but I don't have the URL. (This
specific example actually maps a publicly available
PDF to a file path, then streams it, but it would be trivial
to modify it to stream a file outside the web tree.)
=====================
'load the file and stream it to the browser
'set correct content type
Response.ClearContent()
Response.ClearHeaders()
If Instr(1, LCase(theDocumentURL), ".pdf", 1)<>0
'arrgh, I guess we'll skip this complicated part for NT
Dim theUserAgentPlatform as String=Request.Browser.Platform
If (theUserAgentPlatform.IndexOf("MSIE") > -1) and
(theUserAgentPlatform.IndexOf("WinNT") = -1) Then
Response.ContentType = "application/pdf"
'some fancy footwork to handle certain versions of IE
Dim userAgent As String
userAgent= Request.UserAgent
If userAgent.IndexOf("contype") > -1 Then
'Just send the mime/type
Response.ContentType = "application/pdf"
Response.End
End If
'even the "Fixed" versions of IE still send TWO requests. So,
'we want to detect the second request and not return the whole thing again.
'For reasons unknown to me, IE doesn't include the Accept-Language header
'when making this second call, so, we have them use what has already been
'sent by saying "Not-Modifed":
Dim Language
Language = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
If Language = "" then
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.AddHeader ("Last-modified", "Mon, 01 Sep 1997 01:03:33 GMT")
Response.Status = "304 Not Modified"
Response.End
End If
Else
Response.ContentType = "application/pdf"
End If
Else
Response.ContentType = "text/HTML"
End If
'Get the physical path to the file.
Dim FilePath as String = MapPath(Server.URLDecode(theDocumentURL))
'Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath)
Response.Flush()
Response.Close()
More information about the thelist
mailing list