iarp Posted May 8, 2008 Share Posted May 8, 2008 Hey, I have this function: function site_name() { include_once('mysql_connect.php'); $query = "SELECT site_name FROM " . TBL_CONFIG; $result = @mysql_query($query); $row = mysql_fetch_array($result, MYSQL_ASSOC); if ($result) { echo $row['site_name']; } } which i use in my header title: <title><?php site_name(); ?></title> in my login page i use: // Validate the email address. if (!empty($_POST['username'])) { $un = escape_data($_POST['username']); } else { echo '<p><font color="red" size="+1">You forgot to enter your username!</font></p>'; $un = FALSE; } function escape_data($data) { if (ini_get('magic_quotes_gpc')){ $data = stripslashes($data); } if(function_exists('mysql_real_escape_string')) { global $dbc; $data = mysql_real_escape_string(trim($data), $dbc); } return $data; } Site_name is interfering with escape_data some how and you can't login if i leave site_name(); in there, but if i comment it out it works fine. Am i missing something? If a user tries to login, they only see "Please try again." because username and pass get blanked out by the escape_data problem. Full login page: <?php include('./includes/header.php'); if (isset($_POST['submitted'])) { // Check if the form has been submitted. require_once ('./includes/mysql_connect.php'); // Connect to the database. // Validate the email address. if (!empty($_POST['username'])) { $un = escape_data($_POST['username']); } else { echo '<p><font color="red" size="+1">You forgot to enter your username!</font></p>'; $un = FALSE; } // Validate the password. if (!empty($_POST['pass'])) { $p = escape_data($_POST['pass']); } else { $p = FALSE; echo '<p><font color="red" size="+1">You forgot to enter your password!</font></p>'; } if ($un && $p) { // If everything's OK. // Query the database. $query = "SELECT user_id, first_name, userlevel FROM " . TBL_USERS . " WHERE (username='$un' AND password=SHA('$p')) AND active IS NULL"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (@mysql_num_rows($result) == 1) { // A match was made. // Register the values & redirect. $row = mysql_fetch_array ($result, MYSQL_NUM); mysql_free_result($result); mysql_close(); // Close the database connection. $_SESSION['user_id'] = $row[0]; $_SESSION['first_name'] = $row[1]; $_SESSION['userlevel'] = $row[2]; // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST']; // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/index.php'; ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { // No match was made. echo '<p><font color="red" size="+1">Either the username and password entered do not match those on file or you have not yet activated your account.</font></p>'; } } else { // If everything wasn't OK. echo '<p><font color="red" size="+1">Please try again.</font></p>'; } mysql_close(); // Close the database connection. } // End of SUBMIT conditional. ?> <h1>Login</h1> <form action="login.php" method="post" class="contact_login"> <p><label>Username:</label> <input type="text" name="username" size="20" maxlength="40" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?><?php if(isset($_GET['username'])) echo $_GET['username']; ?>" /></p> <p><label>Password:</label> <input type="password" name="pass" size="20" maxlength="20" value="<?php if(isset($_GET['temppassword'])) echo $_GET['temppassword']; ?>" /></p> <div align="center"> <input type="submit" name="submit" value="Login" /><br /> <small><a href="../forgot_password.php">Forgot Password</a> | <a href="../register.php">Register</a></small> </div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./includes/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/104767-solved-functions-interfering/ Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 $result = mysql_query($query) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/104767-solved-functions-interfering/#findComment-536310 Share on other sites More sharing options...
iarp Posted May 8, 2008 Author Share Posted May 8, 2008 No errors, just Please Try Again. Link to comment https://forums.phpfreaks.com/topic/104767-solved-functions-interfering/#findComment-536317 Share on other sites More sharing options...
DarkWater Posted May 8, 2008 Share Posted May 8, 2008 Don't include the mysql_connect.php (I think it was named that) inside the function, but instead include it before the function so it's only included once. Link to comment https://forums.phpfreaks.com/topic/104767-solved-functions-interfering/#findComment-536322 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 ??? Link to comment https://forums.phpfreaks.com/topic/104767-solved-functions-interfering/#findComment-536324 Share on other sites More sharing options...
iarp Posted May 8, 2008 Author Share Posted May 8, 2008 Don't include the mysql_connect.php (I think it was named that) inside the function, but instead include it before the function so it's only included once. Worked, thanks. My understanding for include_once was that it could be included wherever you wanted on the page and it only be evaluated once. Link to comment https://forums.phpfreaks.com/topic/104767-solved-functions-interfering/#findComment-536326 Share on other sites More sharing options...
DarkWater Posted May 8, 2008 Share Posted May 8, 2008 It's never a good idea to include files inside a function, usually. >_> Link to comment https://forums.phpfreaks.com/topic/104767-solved-functions-interfering/#findComment-536327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.