943,892 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 551
  • PHP RSS
May 2nd, 2009
0

New structure for PHP pages

Expand Post »
I like to script php, and lately i was looking for a way to create a 100% dynamic page in php, with the least possible overhead and create a rich user experiance.

I say this is a "New" PHP structure because I have come up with the idea myself, that does not go to say that no one has come up with this before me.

The structure is simple in its conception, by using 2 variables, one is whether the user is logged on and the other is whether the user has requested a specific page.

The main page, simply index.php in my case, is what i would refer to as a key page. without the first page none of the links on any other pages will work if they are made in a relative position to the first page.

By using the PHP include statement you can include the page with the name equal to the pagename variable i mentioned above, thus the "key" page can be a shell for the rest of the pages to be included into and you can have a whole website based on a single page name, in my case index.php.

as i said, the coding behind the paging was simple:

at the beggining of the page:

PHP Syntax (Toggle Plain Text)
  1. <?php session_start(); $loggedin=@$_SESSION['loggedin']; ?>

and in the space you wish to have the data incorporated into the shell:

PHP Syntax (Toggle Plain Text)
  1. <?PHP
  2.  
  3. $pagename=@$_POST['page'];
  4.  
  5. if(Empty($loggedin) && Empty($pagename))
  6. include("NLI.php");
  7.  
  8. if(Empty($pagename) && !Empty($loggedin))
  9. die('<center><h3>ERROR: There seems to be an error in the page you are vieweing</h3><br>please report this error code: 1001</center>');
  10.  
  11. if(!Empty($pagename))
  12. include("$pagename");
  13.  
  14. ?>

Where loggedin is a simple binary variable, stating weather they are logged in or not, and pagename is the page to display if they are logged in, the site is operated by forms and session variables.


I really enjoyed creating this site, and in my own opinion, i would think this would increase the security of the site itself, but im still a novice at PHP and i hope someone finds this information useful!
Similar Threads
Reputation Points: 10
Solved Threads: 4
Junior Poster
Merlin33069 is offline Offline
126 posts
since May 2008
May 2nd, 2009
0

Re: New structure for PHP pages

You made a huge security risk for yourself.

Including pages based on $_POST data without proper validation can lead to serious security risks. I can include files from other servers and get sensitive information.

I have been using this kind of method for awhile, a little more complex but the same principle.
Last edited by kkeith29; May 2nd, 2009 at 12:57 am.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
May 2nd, 2009
0

Re: New structure for PHP pages

hmm, ok, i changed it so its a little different and now it will only include the files which are on the server, under the includes directory, and those files only operate if you are logged in, eg the login check, and all pages regarding a change, such as changing personal information, require you to reenter your password.

the new code for that part of the page is:

PHP Syntax (Toggle Plain Text)
  1. <?PHP
  2.  
  3. $pagename=@$_POST['page'];
  4. $username=@$_SESSION['username'];
  5.  
  6. if(Empty($loggedin) && Empty($pagename))
  7. include("includes/NLI.php");
  8.  
  9. if(Empty($pagename) && !Empty($loggedin))
  10. include("includes/home.php");
  11.  
  12. if(!Empty($pagename))
  13. include("includes/$pagename");
  14.  
  15. ?>

as i said i am still a novice, i just like the idea of having it all based on one page
Reputation Points: 10
Solved Threads: 4
Junior Poster
Merlin33069 is offline Offline
126 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Math unable to account for 1000??
Next Thread in PHP Forum Timeline: Wordpress Image Question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC