Monday, 15 February 2010

PHP code in html -


I'm not exactly behind PHP, so I'm sorry if I'm stupid

I am trying to implement a login futation, but I am unable to work the php part. Is there a code where writing the code before the html tag is wrong? Please advise.

  & lt ;? Php "config.php" is required; $ Ls- & gt; Init (); If (isset ($ _ POST ['act_login'])) {$ user = $ _ POST ['login']; $ Passed = $ _ post ['pass']; If ($ user == "" $$ pass == "") {$ msg = array ("error", "username / password wrong!"); } Else {if (! $ Ls-> Login ($ user, $ pass)) {$ msg = array ("error", "username / password wrong!"); }}}? & Gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Sign in & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; General HTML code & lt; / Body & gt; & Lt; / Html & gt;  

OK, user2760642, for whatever I remembered, I The code is slightly set:

  & lt ;? Php include_once "SOMECLASS.PHP"; $ Ls = new SOME_CLASS (); // Log-in pass is included in the method to check if (ISSAT ($ _ POST ['login'])) // Check if the user clicks, press the button. User $ = $ _ post ['login']; $ Passed = $ _ post ['pass']; If ($ user == "" $$ pass == "") {echo "error: username / password wrong!"; } And {if (! $ LS-> login ($ user, $ pass)) {resonant "error: username / password wrong!"; } Other {header ("location: mainpage.php"); // opens the main page because // log-in-pass had all rights}}? & Gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Sign in & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form method = "post" action = "loginpage.php" & gt; Login & lt; Input type = "text" name = "login" /> & Lt; Br / & gt; Password & lt; Input type = "text" name = "pass" /> & Lt; Br / & gt; & Lt; Input type = "submit" value = "click here to enter" /> & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

It is wrong to add a PHP code to the same HTML file because if the user presses the back button, the previous page will be reloaded and the PHP code will be re-executed (it will not be a different php script file With) you were remembering the login and password asking form Finally, I added the class to check the login and password in the database (AoExl. PHP).

You can copy and paste this code into a text file called the .php file, and save it to the www subdirectory. You can do this in the left (or lamp or humid) directory, Run from your browser's address bar with the local host / login page. If this does not work, try localhost: 80 / loginpage.php (if it does not turn on, call Houston because we have a problem).

I hope this helps you to learn PHP.


No comments:

Post a Comment