Loading an existing html file into a browser

How can I load an existing HTML file into a browser from within a C cgi script? I 'm currently creating the HTML file on the fly but I want to create it only once and put it in a directory and then force the browser to reference it..
Who is Participating?
ozoConnect With a Mentor Commented:
Location: http://some.machine/some.directory/some.doc

Refresh: 0; URL=http://some.machine/some.directory/some.doc
Content-type: text/html

Content-type: text/html

<HTML><HEAD><meta http-equiv="refresh" content="0; url=http://some.machine/some.directory/some.doc">
print "Content-type: text/html\r\n\r\n";

read html file and write the whole file to stdout

Or, to force the browser to reference it

print "Location: http://some.machine/some.directory/some.doc\r\n\r\n";
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

barlavAuthor Commented:
I don't want to write a file out to stdout when it's already in existence. I want to force the browser to reference it. ozo's comment is close to the answer that I'm looking for but it doesn't work. I tried your answer ozo but it just creates a webpage that displays literally  "Location: http://some.machine/some.directory/some.doc\r\n\r\n" and not the html document that resides there.
barlavAuthor Commented:
  Your answer worked when I didn't set the MIME type ahead of time. Since you headed me in the right direction I'll be happy to award you the points if you submit your comment as an answer.
That is one way of doing this, alternatively you could try the following.

  print "Content-type: text/html\n\n";              # HTTP header
  print "<SCRIPT LANGUAGE=\"JavaScript\">\n";
  print "window.location.replace = '**URL**'\n";
  print "</SCRIPT>\n";

where **URL** is the URL of the page that you want to display.

barlavAuthor Commented:
It seems that the way I'm doing it now is much easier. Thanks for your answer chuckie_worm but I think it's only fair that I give the points to ozo since he put me in the right direction.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.