suhail Posted January 4, 2014 Share Posted January 4, 2014 I was trying to make a php logon page with root password only. I declared the contents of the logon page with the following contents config.php <?php define('hostname','localhost'); define('dbuser','root'); define('dbpass','rootpass123'); define('dbname','infos') //define login credentials define('rootpass','rootuser1'); ?> Now i wanted to include it in my html i decide to include it in the main php file like this <!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>login</title> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; } --> </style> </head> <body> <?php require_once(dirname(__FILE__) . "/config.php"); include 'config.php'; if(isset($_POST['submit'])) { if(rootpass!==rootpass1) { print"Wrong Password"; } else{ header("Location: http://www.google.de"); } } ?> <div align="center"> <table width="559" border="0"> <tr> <td width="553"> </td> </tr> <tr> <td><div align="center"> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>""> <table width="459" border="0"> <tr> <td width="164"><div align="center"><span class="style1">Root Password </span></div></td> <td width="245"><label> <input name="rootpass" type="password" id="rootpass" /> </label></td> </tr> <tr> <td> </td> <td><label></label></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="login" /></td> </tr> </table> </form> </div></td> </tr> </table> <blockquote> <table width="1149" border="0"> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td><div align="center" class="style1">Soldier Bot © 2014 All Rights Reserved </div></td> </tr> </table> </blockquote> </div> </body> </html> when i run it i get errors like this What could go wrong? Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted January 4, 2014 Share Posted January 4, 2014 What could go wrong? Too many things. Start with the path. Quote Link to comment Share on other sites More sharing options...
suhail Posted January 4, 2014 Author Share Posted January 4, 2014 (edited) Too many things. Start with the path. i am a newbie to this kind of stuff. How do i go about it, implemented code. Kindly show me. I would like to learn this. the config is included in this path ../config/config.php cos thats where the file is. Do i include it like this include '../config/config.php' Edited January 4, 2014 by suhail Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted January 4, 2014 Share Posted January 4, 2014 First, check how to find the computing path to the config.php file for your operating system (windows). Second, don't try to include the same path twice in different variants! Use either include (include_once) or require (require_once). Third, I don't see when you defined a rootpass1 constant in your script to compare the values with the rootpass constant. Quote Link to comment Share on other sites More sharing options...
suhail Posted January 4, 2014 Author Share Posted January 4, 2014 Ok i fixed one part. but the part that checks for the rootpassword from the config.php file is giving me issues, i am lost somehow here is my code. <!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>login</title> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; } --> </style> </head> <body> <?php include_once'C:\wamp\www\soldierbot\panel\config\config.php'; if(isset($_POST['submit'])) { $rootpass = $_POST['rootpass']; if(rootpass!==rootpass1) { print"Wrong Password"; } else{ header("Location: http://www.google.de"); } } ?> <div align="center"> <table width="559" border="0"> <tr> <td width="553"> </td> </tr> <tr> <td><div align="center"> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>""> <table width="459" border="0"> <tr> <td width="164"><div align="center"><span class="style1">Root Password </span></div></td> <td width="245"><label> <input name="rootpass" type="password" id="rootpass" /> </label></td> </tr> <tr> <td> </td> <td><label></label></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="login" /></td> </tr> </table> </form> </div></td> </tr> </table> <blockquote> <table width="1149" border="0"> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td><div align="center" class="style1">Soldier Bot © 2014 All Rights Reserved </div></td> </tr> </table> </blockquote> </div> </body> </html> Pls help me. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted January 4, 2014 Share Posted January 4, 2014 (edited) PHP is NOT C $rootpass = $_POST['rootpass']; if(rootpass!==rootpass1) Which one is a constant and variable? Edited January 4, 2014 by jazzman1 Quote Link to comment Share on other sites More sharing options...
suhail Posted January 4, 2014 Author Share Posted January 4, 2014 Ok, Please just help me correct it. To check for the rootpass from the config.php and if it matches the password rootpass1 it should redirect to google(which should be the second page) or dashboard that's what I want it to do. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted January 4, 2014 Share Posted January 4, 2014 You need to compare the value from "rootpass" constant and value from html input field, named - rootpass! Try, $rootpass = trim($_POST['rootpass']); if($rootpass != rootpass) { print"Wrong Password"; } else{ header("Location: http://www.google.de"); exit; // don't forget to call the exit command to terminate the script } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.