Jump to content

Recommended Posts

Posted

Hello,

 

I have another problem now:

 

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.

 

Is there a way PHP can print php files? Any help would be appreciated, thanks. :P

Posted

Perhaps you can include the whole file?

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.

 

If you want it to print the page on another location, that's a different story.

Posted

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.

 

Something else to do is fopen($Page); then print its contents.

Posted (edited)

Deno, I forgot about one thing:

 

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.

 

Use a numbering method instead. like index.php?page=x, where x is a number and then, on index.php you'd have:

>switch($_GET['page'])
{
  case 1:
  include "page1.php";
  break;

  case 2:
  include "page2.php"
  break;

  ...

  default:
  // Do nothing or include a default page here
}

 

Hope this helps :)

Edited by TCH-Raul
Posted (edited)

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.

Edited by TCH-Raul

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...