Jump to content

[SOLVED] Best PHP App Design - including functions, where to post forms, etc


dcnoren

Recommended Posts

First post here - hopefully its not too long  :D

 

Ok, I'm fairly knowledgeable in PHP, and have done several web apps that use lots of PHP and MySQL. Problem with all of them is that they are very, very messy. Especially once you throw in jQuery and AJAX.

 

So, I'm going to try to keep my rambling down and keep the meat of my questions.

 

When designing a site, I always have an index.php page that includes in other page data like this:

 

index.php?page=about then it includes all of the about.php content. I stick a variable in index.php and about.php checks for that variable, and if it is there, it'll spit the content - if not (i.e. a user just called about.php, not index.php?page=about) it'll exit. I do this so all of my pages have one uniform look and feel. Yes, I have plenty of security measures in place to prevent including other unauthorized pages.

 

So, since EVERY page on my site that a user visits is loaded through index.php, inside of the index page I include my function lists, database connections, site configs, etc.

 

But, when you start adding AJAX, those AJAX scripts need to access that info, too - so I include the includes into those AJAX scripts. But this is where relative includes start making a mess - so I now ALWAYS set the php working directory to the location that index.php is in, and everything is included or called relative from that location. Makes things a little easier.

 

I've also started making everything only call one include file, via include_once, which then include_once's all the necessary files inside of that - again just to clean things up.

 

Anything wrong so far? Good? Bad?

 

 

 

Ok. So now for forms in PHP. Lets say the user logs in - that login script could be located on any page, if its in a sidebar. If a user submits data, that data could be submitted on several different pages in some cases - or even via AJAX. So what I've always done is have ANY form submission ALWAYS go through a page called "process.php" which processes ANY form submission. User logs in? Then it calls the login if/then in the process page. User changes profile pictures? Then it calls the profile picture if/then, etc. From there, the user could be either directed via header to the next logical page (whether it be the same page, or a members page, or what have you), OR the process.php page could show the results (thank you for leaving feedback) or something like that.

 

I know the other alternative is to have the page which has the form process the data, and just have the server submit the form to the same page (server self or whatever that variable is), and have the page check for submitted data. I've never used that, because it makes things strung all over the place, and sometimes GET variables in the URL throw things off.

 

Is there a different way of doing things? Is the process page good, bad, ugly?

 

Let me know if you have any input. Thanks :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.