OO PHP - A first attempt

Associate
Joined
8 Mar 2007
Posts
88
Hi there,

I'm in the very early stages of making a new website which i have decided to do in OO PHP (as i have never used it in an OO way and know a bit of php so thought it would be good to experiment).

This question i'm about to ask could isn't an OO question as such but more a structure question.

If i have a register page complete with HTML form (or any page with a form and action), in your opinion where is it best to put the action?

I've seen some sites where the action is the page itself and the php code is contained within the top of the file i.e if $submit then register user else carry on and display page

And i've also seen some where the action would be on a totally different page that contained no html

e.g if you have a file called register.php then the action may be "actions/register_user.php"

I think for neatness sake i'd like to go for the latter and have the actions in a separate php file that way the code could be performed and then i could redirect the user to the sucess page or back to the register form highlighting errors.

The thing that puts me of doing this is having to use header ( ' Location:http://www.somesite.com/here.php') as the address in the users address bar remains the same as the page that did the redirect.

I hope this makes sense.

Thanks in advance for any help...
 
my preference is to submit the form to self and do the process at the top of the page. it doesn't make your source files too dirty because, writing in an OOP style, you shouldn't have too much php up there (except anything to assign a logged-in message to the user or something). If you think about every form you could potentially have, and all the extra files you'd need if you were submitting to a new page everytime, you'd have a lot of superfluous pages.
 
same as Sic here put you code at the top of the same page. 90% of the php doing the work after that should be in seperate classes that you include and create objects of then just call the nessesary functions such as.

login(username, password)

that's basically it really so no need to clutter up your webserver with pointless extra files that do the work of another page.
 
Back
Top Bottom