I have this idea for a website that I can't seem to solve. I created an intro page where there's a username and a password to type and two buttons, a login button and a register button.
What I wanted to do is when the login button is pressed it compares the username and the password with database entries, if they're available, it would redirect the client to homepage. If not, the lightbox would appear for registration.
When both buttons are click, nothing happens :/..
Please help us out by using [code][/code] or [php][/php] around your code excerpts ... it simplifies page navigation and (in the case of PHP) can assist with debugging due to syntax highlighting.
Your code contains some problems. Your design may, also, contain some problems. For example, you say that this is the code for your login page. Yet, I see the authentication code as well, and a PHP header() call after what appears to be the <head> section of an HTML page. It could be that your design for the system has a flaw in its logical flow.
You say "clicking doesn't produce any effect" ... Do you have any further information that could tell us what IS working and/or happening? Perhaps you could examine your server's error logs, or Firebug/Chrome debugger's error console, and see if there are any specific errors we could help with?
/!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade!/!!!\ ereg() is deprecated --- don't use it!
dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket
So the light box was working just fine. But I needed to do the authentification for the username and password and didn't know what to do so I wrote the code above..
Well, authentication is kind of like gaining entry to a high-brow party. You give your name (credentials), the maitre'd checks the guest list and tells you if you can enter or not.
To do this on the web, you have to submit a form, get a response from the server, and then go to the appropriate location.
The "standard" way to handle this, prior to a few years ago, was to present an HTML login form, have that form submitted to a handler script, and have the handler tell the browser where to go (in this case, to the homepage, or to a registration page).
If you've never written an authentication system before, I'd recommend you try the standard way first.
The plan that you seem to have in mind appears to me to be a more advanced concept; that is, a form appears on the page, pushing the button contacts the server without re-loading the page and, depending on the result of the authentication attempt you will either send the browser to a new location or present another form. If you want to do this, you are going to be very careful in planning your application, and you really need to know what each technology (HTML, PHP, Javascript, and for the purposes of this example, "AJAX") can do to help you meet your goal.
For one thing, you'll not be able to use PHP's header() function to redirect the browser after an authentication attempt unless the page gets re-loaded ... a system like I think you are attempting to create would have to use Javascript to accomplish this redirection.
/!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade!/!!!\ ereg() is deprecated --- don't use it!
dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket
If your login form is a separate page, you could have it point to this and put the registration part last, after the header() call; just make sure that any HTML output comes after the code above. This would include whitespace, any echo() or print() statements in PHP, HTML tags, and, of course, the JS needed for the lightbox effect.
/!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade!/!!!\ ereg() is deprecated --- don't use it!
dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket
but can I put the authentication in another function there too or will it not work properly? cause I already tried it and it sort of ruined the hole code (the lightbox wont appear any more upon clicking the register button)
It seems as if you are mixing javascript with PHP - but they are two totally different beasts.
PHP happens on the webserver.
Javascript happens in the user's web browser.
As Dalecosp said.. as you are sticking with the 'simple' process, keep PHP and js separate
It's perfectly fine to put your log in form in the chunk of html that appears via the lightbox and when it gets submitted a bit of PHP will run on the webserver and perform the log in checks...
Last edited by cretaceous; 12-13-2012 at 12:30 PM.
Bookmarks