Desperate for help with a PEAR login form - need this on one page
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Desperate for help with a PEAR login form - need this on one page
Hi all, this is a bit of a last resort as I've seen web based programming questions rarely get noticed on this site, I really am desperate though, I've asked a bunch of other forums and i've been completely ignored or provided with useless ideas.
Basically I have 2 pages, a login page which has 2 fields, email and passwords. The second page is an error checking page which does 2 things - it sends the details via PEAR to a seperate server and awaits a response, if theres an error (e.g NO_EMAIL, NO_PASSWORD, ACCOUNT_LOCKED) then a 'friendlier' message is displayed on the error checking page. What I REALLY want is just one page, the login page to do the error checking and then get sent to a completely seperate page. I've enclosed some of the error checking page for people to view (theres lots of coding missing here and this does work 100% before people comment on that):
Code:
$params = array('email' => $email,'password' => $password,'service' => 'API v1.0');
$auth = $client->call('getAuthToken', $params);
// Check for a fault
if ($client->fault) {
$fault = $auth['faultstring'];
switch ($fault) {
case "NO_EMAIL":
echo 'Email address missing';
break;
case "NO_PASSWORD":
echo "Password missing";
break;
case "LOGIN_INVALID":
echo "email or password is incorrect";
break;
case "ACCOUNT_LOCKED":
echo "The account has been locked.";}
}else {
$err = $client->getError();
if ($err) {
echo 'There seems to be a server side error, please send a ticket along with this refereces: $err to the admin';}
else {
echo header("Location: http://the_page_in_question.com");}
}
exit;
This is just a bit of conditional error checking. If anyone has any examples or pages which may be of use please help. Not bothered how this is coded or how errors come up, just need some help.
Last edited by genderbender; 07-11-2008 at 03:05 PM.
Not certain by what you mean by "I've seen web based programming questions rarely get noticed on this site".
But anyway let's move on. The concept of a page is fairly fluid so I'm not totally certain what your are requesting but in similar situations rather than having echo statements, I store the strings in a variable then when I am ready to send the data back to the client I echo out the whole string. This helps to make the code more flexible in that it can be used in a variety of settings a login screen on its own an login embedded within a div the same code can also be implemented in an Ajax driven site.
So your above code can be run and if you are in the if (error condition) then you can append the login screen code (which I would have placed in a function making it a simple call) to the string.
I just meant questions about HTML or SQL or PHP or any web based language don't usually get a response from many programming forums. They seems less popular than languages like C++, java etc.
Anyway the idea behind this is to have my error catching code and my login page on a single page, then if there are no errors send the user off to an accounts page. I just want the error codes on the same page and not moving from one page, to another and then to another as this is a) ugly, b)slow(ish).
Thanks for your help anyway, I'll keep on working at it. Guess I'll need a do while loop or something, I've no idea where to start.
As I understand your problem you don't need a while loop, roughly you could structure you code as follows:
Code:
IF there are login values in the $_POST THEN
| attempt to authorise the user
| IF there are errors THEN
| | Set up an error string
| | Set up the login Form
| ELSE
| | Display the accounts data
| ENDIF
ELSE
| Set up the login Form
ENDIF
Since you are setting up the login form twice you can put that code into a function.
You would also need to consider what to do if the user is already logged in (check on a session variable and go directly to the appropriate accounts data page)
Ahhh, thanks. So where does the form go, PHP_SELF? Then loginvalid (or whatever) if there are no errors. As the errors are generated on a seperate server this is the confusing bit. Anyway thanks a lot, i'll work on it more tonight and see how i get on
Thought I'd add this to help people understand, I realise the data must be sent to someone else to do the error processing, what I can settle with is a response sent back to the login page with details. At the moment I have my error checking page, and I've made an if statement which basically echoes the entire site and has some error information in the middle, hideous way of doing it. I've been trying to pass an html variable to a page listing errors, but I don't know how to do that without a submit button (I'm kind of new to pure HTML coding.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.