php - how to change simple session login type into facebook style login? -


i stuck in converting login type of web based application..i got code net in app ask username , when enter it, shows conversation page..but want convert login type proper 1 username , password..i designed login system want use..the codes absolutely working when used individually..when combined wont work..can tell me code after combining these two?

here's code app index.php

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>chat</title> <link type="text/css" rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="css/style.css">   <style> a:link {     color: black; } a:visited {     color: black; }</style> </head>  <body>  <?php session_start();  ?> <div id="wrapper">     <div id="menu">         <p class="welcome">welcome, <b><?php echo $_session['name']; ?></b></p>         <p class="logout"><a id="exit" href="login.php">exit chat</a></p>         <div style="clear:both"></div>     </div>         <div id="chatbox"></div>      <form name="message" action="">         <input name="usermsg" type="text" id="usermsg" size="63" />         <input name="submitmsg" type="submit"  id="submitmsg" value="send" />     </form> </div> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> // jquery document $(document).ready(function(){     //if user submits form     $("#submitmsg").click(function(){            var clientmsg = $("#usermsg").val();         $.post("post.php", {text: clientmsg});                       $("#usermsg").attr("value", "");         return false;     });      //load file containing chat log     function loadlog(){               $.ajax({             url: "log.html",             cache: false,             success: function(html){                         $("#chatbox").html(html); //insert chat log #chatbox div                            },         });     }      //load file containing chat log     function loadlog(){              var oldscrollheight = $("#chatbox").attr("scrollheight") - 20; //scroll height before request         $.ajax({             url: "log.html",             cache: false,             success: function(html){                         $("#chatbox").html(html); //insert chat log #chatbox div                     //auto-scroll                            var newscrollheight = $("#chatbox").attr("scrollheight") - 20; //scroll height after request                 if(newscrollheight > oldscrollheight){                     $("#chatbox").animate({ scrolltop: newscrollheight }, 'normal'); //autoscroll bottom of div                 }                            },         });     }      setinterval (loadlog, 2500);    //reload file every 2500 ms or x ms if w }); </script> <script type="text/javascript"> // jquery document $(document).ready(function(){     //if user wants end session     $("#exit").click(function(){         var exit = confirm("are sure want end session?");         if(exit==true){window.location = 'index.php?logout=true';}           }); }); </script> <?php  if(isset($_get['logout'])){       //simple exit message     $fp = fopen("log.html", 'a');     fwrite($fp, "<div class='msgln'><i>user ". $_session['name'] ." has left chat session.</i><br></div>");     fclose($fp);      session_destroy();     header("location: index.php"); //redirect user } ?>  </body> </html> 

here's code login system login.php

<!doctype html> <!--[if lt ie 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if ie 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]--> <!--[if ie 8]> <html class="lt-ie9" lang="en"> <![endif]--> <!--[if gt ie 8]><!--> <html lang="en"> <!--<![endif]--> <head>   <title>login form</title>   <style> a:link {     color: black; } a:visited {     color: black; }</style>   <link rel="stylesheet" href="css/style.css"> </head> <body> <?php if (!isset($_post['submit'])){ ?>   <h1 class="register-title">welcome</h1>   <form action="<?=$_server['php_self']?>" method="post" class="register">      <div class="register-switch">       <input type="radio" name="type" value="l" id="login" class="register-switch-input" checked>       <label for="login" class="register-switch-label"><a href="login.php"  style="text-decoration:none;" link="#000000" vlink="#000000" alink="#000000">login</a></label>       <input type="radio" name="type" value="r" id="register" class="register-switch-input">       <label for="register" class="register-switch-label"><a href="register.php"  style="text-decoration:none;">register</a></label>     </div>      <input type="text" name="username" class="register-input" placeholder="user name">     <input type="password" name="password"class="register-input" placeholder="password">     <input type="submit" name="submit" value="login" class="register-button">   </form>   <?php } else {     require_once("db_const.php");     $mysqli = new mysqli(db_host, db_user, db_pass, db_name);     # check connection     if ($mysqli->connect_errno) {         echo "<p>mysql error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";         exit();     }      $username = $_post['username'];     $password = $_post['password'];      $sql = "select * users username '{$username}' , password '{$password}' limit 1";     $result = $mysqli->query($sql);     if (!$result->num_rows == 1) {         echo "<p>incorrect password</p>";     } else {         echo "<p>logged in successfully</p>";         // stuffs         header("location: index.php");     } } ?>       </body> </html> 

you need put <?php session_start(); ?> @ top of both pages, before <!doctype or else.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -