Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host=""; // Host name
- $username=""; // Mysql username
- $password=""; // Mysql password
- $db_name=""; // Database name
- $tbl_name=""; // Table name
- // Connect to server and select databse.
- mysql_connect("$host", "$username", "$password")or die("cannot connect to DB");
- mysql_select_db("$db_name")or die("cannot select DB");
- // username and password sent from form
- $uname = $_POST['uname'];
- $passwd = $_POST['passwd'];
- //Checking for empty fields
- if (empty($uname) || empty($passwd)) {
- echo "<html>
- <body>
- <br />
- <h3 align=center>Please fill out all fields.</h3>
- <br />
- <p align=center>
- <a href=index.php>Go back and try again.</a></p>
- <p align=center>If you are not redirected automatically within a few
- seconds then please click on the link above.</p>
- <script type=text/javascript><!--
- setTimeout('Redirect()',3000);
- function Redirect()
- {
- location.href = 'index.php';
- }
- // --></script>
- </body>
- </html>";
- die;
- }
- $uname = mysql_real_escape_string(stripslashes($uname));
- $passwd = mysql_real_escape_string(stripslashes($passwd));
- $sql="SELECT * FROM $tbl_name WHERE username='$uname' and password='$passwd'";
- $result=mysql_query($sql);
- $count=mysql_num_rows($result);
- if($count==1){
- $_SESSION['uname'] = $uname;
- $_SESSION['passwd'] = $passwd;
- Header("Location: userarea.php");
- } else {
- echo "<html>
- <body>
- <br />
- <h3 align=center>Wrong username or password.</h3>
- <br />
- <p align=center>
- <a href=index.php>Go back and try again.</a></p>
- <p align=center>If you are not redirected automatically within a few
- seconds then please click on the link above.</p>
- <script type=text/javascript><!--
- setTimeout('Redirect()',3000);
- function Redirect()
- {
- location.href = 'index.php';
- }
- // --></script>
- </body>
- </html>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement