imithya Posted April 29, 2009 Share Posted April 29, 2009 This is my login script for a blogsite... <?php require("config.php"); if($_POST['submit']) { if (!$db) { $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Could not connect to the database... Please try again later!"); mysql_select_db($dbdatabase, $db); } $sql = "SELECT * FROM logins WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';"; $result = mysql_query($sql) or die("Query failed: " . mysql_error()); $numrows = mysql_num_rows($result); if($numrows == 1) { $row = mysql_fetch_assoc($result); session_start(); $_SESSION['USERNAME'] = $_POST['username']; $_SESSION['USERID'] = $row['id']; header("Location: " . $config_basedir . "index.php"); } else { $username = $_POST['USERNAME']; header("Location: " . $config_basedir . "/login.php?error=1"); } } else { require("header.php"); } if($_GET['error']) { echo "Incorrect login, please try again!"; } ?> <h2>Login</h2> <div class="meta"><?php echo date("F j, Y @ g.iA",time()); ?></div> <br> <div> <form action="<?php echo $SCRIPT_NAME ?>" method="post"> <table> <tr> <td>Username</td> <td><input type="text" name="username" value="<?php echo $username ?>"></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password" value=""></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Login"></td> </tr> </table> </form> </div> <?php require("footer.php"); if ($db) mysql_close($db); ?> But when executed it gives the error concerning page redirection: I dont understand where is the problem on the code.... can someone help me please... Quote Link to comment https://forums.phpfreaks.com/topic/156124-page-redirection-problem-in-login-page/ Share on other sites More sharing options...
ignace Posted April 29, 2009 Share Posted April 29, 2009 Your config.php outputs content and therefor you get these errors, please post config.php for further debugging purposes Quote Link to comment https://forums.phpfreaks.com/topic/156124-page-redirection-problem-in-login-page/#findComment-821860 Share on other sites More sharing options...
radi8 Posted April 29, 2009 Share Posted April 29, 2009 See this post: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/156124-page-redirection-problem-in-login-page/#findComment-821863 Share on other sites More sharing options...
imithya Posted April 30, 2009 Author Share Posted April 30, 2009 Hey i have seen the post on Header errors and have already checked my script for any kind of output prior to redirection... my script does not output anything if it needs to redirect, only a session gets started... but i think that does not cause the problem.... Here is the config.php: <!-- Defines configuration parameters --> <?php $dbhost = "localhost"; $dbuser = "root"; $dbpassword = ""; $dbdatabase = "blogtastic"; $config_blogname = "Blogtastic"; $config_author = "Pooja Gupta & Mukul Sharma"; $config_basedir = "http://127.0.0.1/bb/New%20Folder/"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/156124-page-redirection-problem-in-login-page/#findComment-822435 Share on other sites More sharing options...
avvllvva Posted April 30, 2009 Share Posted April 30, 2009 Try to replace session_start(); into the first line of your code. like below.. <?php session_start(); require("config.php"); Quote Link to comment https://forums.phpfreaks.com/topic/156124-page-redirection-problem-in-login-page/#findComment-822477 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 30, 2009 Share Posted April 30, 2009 In your code this part : <!-- Defines configuration parameters --> Is a html comment and will be output and see by everyone when they view the source. That what broke the header() function used by session_start(). Use PHP comment like that : <?php /* -- Defines configuration parameters -- */ $dbhost = "localhost"; $dbuser = "root"; $dbpassword = ""; $dbdatabase = "blogtastic"; $config_blogname = "Blogtastic"; $config_author = "Pooja Gupta & Mukul Sharma"; $config_basedir = "http://127.0.0.1/bb/New%20Folder/"; ?> You won't get any output visible by the client and fix the problem. avvllvva solution will work for session_start() but not for the header(location:...) later in the php file. Quote Link to comment https://forums.phpfreaks.com/topic/156124-page-redirection-problem-in-login-page/#findComment-822520 Share on other sites More sharing options...
imithya Posted April 30, 2009 Author Share Posted April 30, 2009 oohhh... i removed all the comments from the login.php but didn't consider config.php.... thanx alot I would remove the comments and hopefully it would works.. Quote Link to comment https://forums.phpfreaks.com/topic/156124-page-redirection-problem-in-login-page/#findComment-822622 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.