问题
Can I use HTML Frames with PHP?
I presumed I can do this by..
<?php
session_start();
require("auth.php");
require("do_html_header.php");
if($_SESSION['SESS_admin'] == 0)
require("do_menu.php");
else
require("do_menu3.php");
do_html_header();
print"<h1>Welcome ". $_SESSION['SESS_FIRST_NAME']."!</h1>";
do_menu();
?>
</body>
<frameset rows="50%,50%">
<frame noresize="noresize" src="limits.php" />
<frame noresize="noresize" src="limits.php" />
</frameset>
</html>
I have put it everywhere but it seems not to show up..
Google just confused me.
Thanks in Advance :D
回答1:
You can use PHP with HTML framesets, but you shouldn't be outputting anything in a <body>
element of a frameset page (even then it should be <noframes>
, not <body>
). Content goes within the individual pages contained by your <frame />
elements.
Anyway, don't use frames. PHP as a templating language is meant to help you separate components of your pages by way of includes, rendering framesets completely unnecessary in the first place.
回答2:
Yes, you can use frames. But you'll have to output the actual content in the frameset files, in your case limits.php
. Beware of a few things here:
- Starting the session in the frameset file is ok.
- But you'll also have to session_start() in the limits.php frame content file.
- Likewise the HTTP authentication should be performed in all frame files.
- Do not assume that people cannot access do_menu3.php directly.
I've previously used frames for implementing a NortonCommand-clone for the web, where it's more senseful than CSS-arranging divs. However, handling jQuery is more cumbersome with frames. In regards to PHP it's as simple as treating every frame script as individual entry script.
来源:https://stackoverflow.com/questions/4600648/frames-with-php