Forum Moderators: coopster

Message Too Old, No Replies

General login/signup/database coding issues

         

impact

4:04 am on May 7, 2010 (gmt 0)

10+ Year Member



Hello,

I am a beginner in PHP. I would like to know more about optimizing my server side php codes. This is a general post and there may not be a direct answer to this, so I would be thankful for any sort of help on this.

I usually create a
- login.php
- LoginClass.php

Since I do not know to submit a form data directly to a CLASS so I use login.php to get the $_POST data from the form. Once login.php receives the data it then sends the data to LoginClass.php for the actual login processing.

Similarly I usually create
- signup.php
- SignupClass.php

Since LoginClass.php and SignupClass.php needs to access database, I usually have the database codes as private function in each of this CLASS pages.

Is there any better way to do this? for example, using a abstract class and extending to each of these files?

Or how do you usually handle this things in your programming?

Thank you.

arvind gupta

7:16 am on May 9, 2010 (gmt 0)

10+ Year Member



Hello,

First off, you can directly pass form data to a script by giving the script URL in the form's
action
attribute.

<form name="someform" cation="action_script.php" methos="post">
...
...
</form>


Secondly, I generally tend to create classes for each object, like, if I have a user I'll create a user class which handles all the user related DB manipulation including login.

impact

1:04 pm on May 9, 2010 (gmt 0)

10+ Year Member



hello,

Is there away, I can submit my form data directly to a Class's function or constructor?

Thanks

Readie

4:48 pm on May 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't post directly to a class, you can however do the following:
if(isset($_POST['something']) && !empty($_POST['something'])) {
// Asign to class here
} else {
// Error: please select a value
}

coopster

1:26 pm on May 11, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You don't have to submit form data to a class in order to access the values in a superglobal because PHP's superglobals [php.net] are always available in all scopes.

As far as a single DB connection, you may want to consider a singleton pattern [webmasterworld.com].