New Php Problem

Hello,<br /><br />I have another problem now:<br /><br />This is relating back to my interviews.php page. When I try to select a link, it won't print the page contents. In my database "interviews", I have the following fields: interview_id, name and page. Page contains the filename of the page, that page mainly has one image and a bunch of text. <br /><br />Is there a way PHP can print php files? Any help would be appreciated, thanks. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Perhaps you can include the whole file?<br />It's the simplest trick of all, just place this: include("page"); where you want the script to "print" the file and it will be there.<br /><br />If you want it to print the page on another location, that's a different story.<!--content-->
I'm with Raul here. Back when I used a ?Page=filename.php system for managing pages on my websites, I would just use require($Page); to load it up.<br /><br />Something else to do is fopen($Page); then print its contents.<!--content-->
Deno, I forgot about one thing:<br /><br />be carefull when using such a method for including pages. Someone might try to retrieve files they shouldn't be able to access simply by putting the filename in the URL.<br /><br />Use a numbering method instead. like index.php?page=x, where x is a number and then, on index.php you'd have:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->switch($_GET['page'])<br />{<br />   case 1:<br />   include "page1.php";<br />   break;<br /><br />   case 2:<br />   include "page2.php"<br />   break;<br /><br />   ...<br /><br />   default:<br />   // Do nothing or include a default page here<br />}<!--c2--></div><!--ec2--><br /><br />Hope this helps <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Oh, one more thing: don't use just $Page to get the variable passed in the URL. If 'register_globals' is turned off, your script will fail. Instead, use $_GET['Page']. You should always use $_GET['variable_name'] for variables passed in the URL, $_POST['variable_name'] for variables sent through an HTML form, $_COOKIES['cookie_name'] for cookies, etc... because this way you know your script will always work, whether register_globals is on or off.<!--content-->
 
Back
Top