smc Posted January 22, 2007 Share Posted January 22, 2007 Hello,I am having a problem and I cannot track down the source. I have three pages for my login script. login.php - holds the php code to handle checking the inputted data against the sql starting sessions, etc. login-status.php - This is meant to be included in case something happens that prevents the script from being succesfully ie. blank field or wrong password or username not being in the database. login_result.php is the success page that holds the functions that control whether to show links to staff or admin pages.I have included all these files below.My problem is on login_status.php (placed in /root/templates) and login_result.php (placed in /root/templates) it does not echo my "statustxt" variable which shows the text to the user explaining the problem or success.I am totally baffeled, I've been reviewing it for over 5 hours but can't nail it. Any help you can offer would be much appreciated.Thanks!!login.php[code]<?php/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// login.php //////---------------------------------------------------------------------////// Content Managment System ////// v0.9 ///////////////////////////////////////////////////////////////////////////////// Coded by: Shane Chism ////// [email protected] ///////////////////////////////////////////////////////////////////////////////// File Specifics: ////// ---------------------------------------- ////// File creation: January 21st, 2007 ////// Last file update: January 22nd, 2007 ////// ---------------------------------------- ////// File ID: login.php - Allows staff members to login //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/$cms_root_path = '';include($cms_root_path . 'functions.php');//We call the config.php file later on to know where the website is at and where to route$cms_root_path = '';include($cms_root_path . 'config.php');//Start up the session incase they are already logged in//session_start();//Check to see if they are logged inif(isset($_SESSION['username'])){ $statustxt = $_SESSION['username'].", it seems your already logged in!"; $cms_template_path = '/templates/'; include($scriptlocation . $cms_template_path . 'login_status.php'); die;}if ( $submit != "true" ) { $cms_template_path = '/templates/'; include($scriptlocation . $cms_template_path . 'login_form.php');die;}// NOTE:// $resulttxt will be used to monitor failures or successes in login//This will test to make sure the fields are not emptyif ( $submit == "true" ) {// This will translate the fields into variables PHP can use$username = $_POST['username'] ;$password = $_POST['password'] ;//This will test to make sure the fields are not emptyif ( $username == "" || $password == "" ){ $statustxt = "You left one or more fields blank when logging in. I don't have all day you know.<br /><br />Try <a href=\"/login.php\">logging in</a> again."; $cms_template_path = '/templates/'; include($scriptlocation . $cms_template_path . 'login_status.php'); die;}}//This next line we declare the huge bracket to surround the code. This is just verifying the credentials have been submittedif ( $submit == "true" ) {$username = $_POST['username'] ;$password = $_POST['password'] ;//This will now load the config login information, connect to the DB, select the DB, and then search for a matching username$cms_root_path = './';include($cms_root_path . 'config.php');$conn = mysql_connect ($dblocation, $dbusername, $dbpassword) or die ("Sorry - I got lost and couldn't find the database. Please try back later.");$result = mysql_select_db("$dbdatabase", $conn) or die("Sorry - the database decided to give me trouble. Please try back after I've put it in it's place.");//This checks to see if there are any entries in the table users where the username matches the one just entered$execute = mysql_query("SELECT * FROM users WHERE username='$username'") or die ("Sorry - I couldn't find the table. Try back later.");//This will check to see if there are no matches in the database with the username entered. If so it will trigger our nonamefound functionif (mysql_num_rows($execute) == 0) { nonamefound();}//NOTE: SQL<MODIFIER> will represent the information retrieved from the databasewhile($row = mysql_fetch_array($execute)){ $sqlusername = $row["username"]; $sqlpassword = $row["pass"]; $sqlfirstname = $row["first_name"]; $sqllastname = $row["last_name"]; $sqlposition = $row["position"]; $sqlrank = $row["rank"]; $sqlemail = $row["email"];}//Now we are going to make sure the password is correct, if it isn't then our custom function will return to the error pageif ( $password != $sqlpassword ){ wrongpassword();}else{//We will now start our sessionsession_start();//Now we are going to assign all that information we retrieved from our database to our session so it can be used later$_SESSION['susername'] = $sqlusername;$_SESSION['spassword'] = $sqlpassword;$_SESSION['sfirstname'] = $sqlfirstname;$_SESSION['slastname'] = $sqllastname;$_SESSION['sposition'] = $sqlposition;$_SESSION['srank'] = $sqlrank;$_SESSION['semail'] = $sqlemail;//Now that all of our information is set in the session, we can go ahead and take them to the success page $statustxt = $_SESSION['sfirstname']. " " . $_SESSION['slastname'].", you have succesfully logged in!"; $cms_template_path = '/templates/'; require($scriptlocation . $cms_template_path . 'login_result.php'); //include('http://een.eagleeye5.com/templates/login_result.php');}} //End huge bracket surrounding code?>[/code]login_result.php[code]<?php/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// login_result.php //////---------------------------------------------------------------------////// Content Managment System ////// v0.9 ///////////////////////////////////////////////////////////////////////////////// Coded by: Shane Chism ////// [email protected] ///////////////////////////////////////////////////////////////////////////////// File Specifics: ////// ---------------------------------------- ////// File creation: January 21st, 2007 ////// Last file update: January 22nd, 2007 ////// ---------------------------------------- ////// File ID: login_result.php - Shows results of the login function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/session_start();$cms_root_path = '../';require($cms_root_path . 'functions.php');?><html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <link rel="stylesheet" href="/css/css.css" type="text/css" /> <title>Eagle Eye News :: Login</title> </head> <body> <div align="center" valign="top"> <table border="0" class="defaultframe" valign="top" cellpadding="0" cellspacing="0" id="table5"> <tr> <td height="177" background="/images/header.jpg" width="100%"> <table border="0" width="100%" id="table7" cellspacing="0" cellpadding="0" height="100%"> <tr> <td colspan="8"> </td> </tr> <tr> <td height="26" width="2%"> </td> <td height="26" width="13%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="index.php">HOME</a> </font> </td> <td height="26" width="21%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="topstories.php">TOP STORIES</a> </font> </td> <td height="26" width="18%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="features.php">FEATURES</a> </font> </td> <td height="26" width="15%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="sports.php">SPORTS</a> </font> </td> <td height="26" width="14%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="about.php">ABOUT</a> </font> </td> <td height="26" width="16%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="contact.php">CONTACT</a> </font> </td> <td height="26" width="2%"> </td> </tr> <tr> <td height="9" colspan="8"></td> </tr> </table> </td> </tr> <tr> <td> <table border="0" width="735" id="table6" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" height="100%"> <tr> <div align="center"> <td> <table border="0" cellpadding="0" cellspacing="0" width="100%" id="table8" height="100%"> <tr> <td valign="top"> <div align="center"> <table border="0" cellpadding="0" cellspacing="0" width="100%" id="table13" height="100%"> <tr> <td width="10" height="18"></td> <td valign="top" height="18"> </td> <td width="13" height="18"></td> </tr> <tr> <td width="10" height="18"></td> <td valign="top" height="18"> <b> <font face="Arial Black"> Staff - Login </font> </b> </td> <td width="13" height="18"></td> </tr> <tr> <td width="10" height="18"></td> <td valign="top" height="18"> <hr> </td> <td width="13" height="18"></td> </tr> <tr> <td width="10" height="14"></td> <td valign="top" height="14"></td> <td width="13" height="14"></td> </tr> <tr> <td width="10"> </td> <td valign="top"> <font face="Arial"> <?php echo "$statustxt" ?> <br /> <br /> <br /> <b>Panel links:</b> <br /> <br /> <a href="/logout.php">Logout</a> <br /> <br /> <?php stafflink(); ?> <br /> <br /> <?php adminlink(); ?> </td> <td width="13"> </td> </tr> <tr> <td width="10" height="12"></td> <td valign="top" height="12"></td> <td width="13" height="12"></td> </tr> </table> </div> <p></td> </tr> </table> </td> </div> </tr> </table> </td> </tr> <tr> <td height="12" background="/images/footer.jpg"> </td> </tr> </table> </div> <p> </p> </body></html>[/code]login_status.php[code]<?php/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// login_status.php //////---------------------------------------------------------------------////// Content Managment System ////// v0.9 ///////////////////////////////////////////////////////////////////////////////// Coded by: Shane Chism ////// [email protected] ///////////////////////////////////////////////////////////////////////////////// File Specifics: ////// ---------------------------------------- ////// File creation: January 21st, 2007 ////// Last file update: January 22nd, 2007 ////// ---------------------------------------- ////// File ID: login_status.php - Template page for login.php //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/$cms_root_path = '../';@include($cms_root_path . 'functions.php');?><html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <link rel="stylesheet" href="/css/css.css" type="text/css" /> <title>Eagle Eye News :: Login</title> </head> <body> <div align="center" valign="top"> <table border="0" class="defaultframe" valign="top" cellpadding="0" cellspacing="0" id="table5"> <tr> <td height="177" background="/images/header.jpg" width="100%"> <table border="0" width="100%" id="table7" cellspacing="0" cellpadding="0" height="100%"> <tr> <td colspan="8"> </td> </tr> <tr> <td height="26" width="2%"> </td> <td height="26" width="13%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="index.php">HOME</a> </font> </td> <td height="26" width="21%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="topstories.php">TOP STORIES</a> </font> </td> <td height="26" width="18%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="features.php">FEATURES</a> </font> </td> <td height="26" width="15%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="sports.php">SPORTS</a> </font> </td> <td height="26" width="14%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="about.php">ABOUT</a> </font> </td> <td height="26" width="16%"> <p align="center"> <font face="Arial Black"> <a class="nav" href="contact.php">CONTACT</a> </font> </td> <td height="26" width="2%"> </td> </tr> <tr> <td height="9" colspan="8"></td> </tr> </table> </td> </tr> <tr> <td> <table border="0" width="735" id="table6" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" height="100%"> <tr> <div align="center"> <td> <table border="0" cellpadding="0" cellspacing="0" width="100%" id="table8" height="100%"> <tr> <td valign="top"> <div align="center"> <table border="0" cellpadding="0" cellspacing="0" width="100%" id="table13" height="100%"> <tr> <td width="10" height="18"></td> <td valign="top" height="18"> </td> <td width="13" height="18"></td> </tr> <tr> <td width="10" height="18"></td> <td valign="top" height="18"> <b> <font face="Arial Black"> Staff - Login </font> </b> </td> <td width="13" height="18"></td> </tr> <tr> <td width="10" height="18"></td> <td valign="top" height="18"> <hr> </td> <td width="13" height="18"></td> </tr> <tr> <td width="10" height="14"></td> <td valign="top" height="14"></td> <td width="13" height="14"></td> </tr> <tr> <td width="10"> </td> <td valign="top"> <font face="Arial"> <?php echo "$statustxt" ?> <br /> </td> <td width="13"> </td> </tr> <tr> <td width="10" height="12"></td> <td valign="top" height="12"></td> <td width="13" height="12"></td> </tr> </table> </div> <p></td> </tr> </table> </td> </div> </tr> </table> </td> </tr> <tr> <td height="12" background="/images/footer.jpg"> </td> </tr> </table> </div> <p> </p> </body></html>[/code]functions.php[code]<?php/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// functions.php //////---------------------------------------------------------------------////// Content Managment System ////// v0.9 ///////////////////////////////////////////////////////////////////////////////// Coded by: Shane Chism ////// [email protected] ///////////////////////////////////////////////////////////////////////////////// File Specifics: ////// ---------------------------------------- ////// File creation: January 20th, 2007 ////// Last file update: January 22nd, 2007 ////// ---------------------------------------- ////// File ID: functions.php : Functions definition File //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*//*//This function will connect to the database using the credentials in config.php - Disabled 1/21 for lack of probable usefunction dbconnect(){$cms_root_path = './'; //Some kind of security in place to prevent out of function password variable calling, added to get around it (following line as well)include($cms_root_path . 'config.php');$dbh=mysql_connect ($dblocation, $dbusername, $dbpassword) or die ("Sorry - we could not connect to our database. Please try back later.");mysql_select_db ("$dbdatabase") or die("Sorry - we encountered a database error. Please try back later.");}*///We call the config.php file later on to know where the website is at and where to route$cms_root_path = '';include($cms_root_path . 'config.php');//This function will execute SQL defined in a file and inject it into the SQLfunction injectsql($sql){$cms_root_path = './';include($cms_root_path . 'config.php');$dbh=mysql_connect ($dblocation, $dbusername, $dbpassword) or die ("Sorry - we could not connect to our database. Please try back later.");$rs=mysql_query($sql,$dbh) or die ("Sorry - we could not execute the SQL command. Please try back later.");}//This function will be used in login.php in the event that a user enters a username not found in our DBfunction nonamefound(){ $cms_root_path = ''; include($cms_root_path . 'config.php'); $statustxt = "Sorry, that username was not found in our database."; $cms_template_path = '/templates/'; include($scriptlocation . $cms_template_path . 'login_status.php'); die;}//This function will be used in login.php in the event the user enters a password not matching the usernamefunction wrongpassword(){ $cms_root_path = ''; include($cms_root_path . 'config.php'); $statustxt = "Sorry, that password does not match that username."; $cms_template_path = '/templates/'; include($scriptlocation . $cms_template_path . 'login_status.php'); die;}//Function for showing the link to the staff panelfunction stafflink(){ if ( $_SESSION['srank'] == "staff" || $_SESSION['srank'] == "admin"){ $displaytxt = "<a href=\"/staff/index.php\">Staff panel</a>"; echo $displaytxt; } else { $displaytxt = ""; echo $displaytxt; }}//Function for showing the link to the admin panelfunction adminlink(){ if ( $_SESSION['srank'] == "admin" ){ $displaytxt = "<a href=\"/admin/index.php\">Admin panel</a>"; echo $displaytxt; } else { $displaytxt = ""; echo $displaytxt; }}//This function will be our sendmail function for registrations.function regemail($destinationemail,$username,$password,$firstname,$lastname,$position){ $mailto = '[email protected]' ; $subject = "Your registration information" ; $uself = 0; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $domain = $_POST['domain'] ; $name = "Eagle Eye 5 Network"; $fullname = $firstname . " " . $lastname; $messageproper = "Thank you for registering on the Eagle Eye 5 network. Here is your registration information:\n" . "\n" . "-------------\n" . "\n" . "Full name: $fullname\n\n" . "Username: $username\n\n" . "Password: $password\n\n" . "Position: $position\n\n" . "Registered e-mail: $destinationemail\n\n" . "-------------\n" . "\n" . "If you have any questions please feel free to contact [email protected].\n" . "\n" . "\n" . "Thank you,\n\n" . "Eagle Eye 5 Network \n\n" . "\n" ; mail($destinationemail, $subject, $messageproper, "From: \"$name\" <$mailto>" . $headersep . "Reply-To: \"$name\" <$mailto>" . $headersep . "X-Mailer: chfeedback.php 2.07" );}?>[/code]If you need any more files please let me knowThanks again!! Link to comment https://forums.phpfreaks.com/topic/35274-failure-to-echo/ Share on other sites More sharing options...
genericnumber1 Posted January 22, 2007 Share Posted January 22, 2007 might want to think about variable scope, you cant define your $statustxt in a function and display it out of the function like, for example, you do here...[code]<?phpfunction nonamefound(){ $cms_root_path = ''; include($cms_root_path . 'config.php'); $statustxt = "Sorry, that username was not found in our database."; $cms_template_path = '/templates/'; include($scriptlocation . $cms_template_path . 'login_status.php'); die;}?>[/code]you could though use globals though, something like this...[code]<?phpfunction nonamefound(){ $cms_root_path = ''; include($cms_root_path . 'config.php'); global $statustxt; // <-- add this $statustxt = "Sorry, that username was not found in our database."; $cms_template_path = '/templates/'; include($scriptlocation . $cms_template_path . 'login_status.php'); die;}?>[/code]this was just one function you do it in, there are others... also, dont forget you can do $GLOBALS['statustxt'] as well if you're more comfortable that way Link to comment https://forums.phpfreaks.com/topic/35274-failure-to-echo/#findComment-166716 Share on other sites More sharing options...
smc Posted January 22, 2007 Author Share Posted January 22, 2007 Didn't have any effectPlus if I made it global wouldn't it interfere with the other functions determining the statustxt? Link to comment https://forums.phpfreaks.com/topic/35274-failure-to-echo/#findComment-166728 Share on other sites More sharing options...
genericnumber1 Posted January 22, 2007 Share Posted January 22, 2007 You've just given too much to look at, can you localize the problem more so I can understand what your issue is better? Link to comment https://forums.phpfreaks.com/topic/35274-failure-to-echo/#findComment-166742 Share on other sites More sharing options...
smc Posted January 22, 2007 Author Share Posted January 22, 2007 I can't localize it, that's the problem. By all my ideas this should be working fine.The problem is *most likely* located in eithier login.php or login_result.php but like I said I have no guarentees Link to comment https://forums.phpfreaks.com/topic/35274-failure-to-echo/#findComment-166753 Share on other sites More sharing options...
genericnumber1 Posted January 22, 2007 Share Posted January 22, 2007 You never seem to be defining the $statustxt outside of a function anyways before displaying it in "login_status.php", I might be missing something though.EDIT: okay apparently I'm missing something, you echo it multiple times and you define it multiple times, I just cant seem to follow the way you're setting it up. Link to comment https://forums.phpfreaks.com/topic/35274-failure-to-echo/#findComment-166754 Share on other sites More sharing options...
smc Posted January 22, 2007 Author Share Posted January 22, 2007 This is the dealI've got functions in login.php running the gauntlet testing to see if the login crednetials past spec.For example:[code=php:0]//This will test to make sure the fields are not emptyif ( $username == "" || $password == "" ){ $statustxt = "You left one or more fields blank when logging in. I don't have all day you know.<br /><br />Try <a href=\"/login.php\">logging in</a> again."; $cms_template_path = '/templates/'; include($scriptlocation . $cms_template_path . 'login_status.php'); die;}}[/code]This checks to make sure the fields aren't empty. If they are it defines the status text and includes the login_status.php page which in turn sees the defined text and echos it, then kills the script.At the bottom you will see[code=php:0]//Now that all of our information is set in the session, we can go ahead and take them to the success page $statustxt = $_SESSION['sfirstname']. " " . $_SESSION['slastname'].", you have succesfully logged in!"; $cms_template_path = '/templates/'; require($cms_template_path . 'login_result.php'); //include('http://een.eagleeye5.com/templates/login_result.php');[/code]This isn't a function since it is at the end of the script and anything that could have been ary has caused the script to die; already. Here it defines the final, success, statustxt then includes the result page which has it's own set of echos and functions.Hope this helps. I'm starting to convulse Link to comment https://forums.phpfreaks.com/topic/35274-failure-to-echo/#findComment-166765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.