brianwilcox Posted February 27, 2015 Share Posted February 27, 2015 Trying to make a home page containing news articles near the center. That being irrelevant, I am having problems making a simple login to the admin page. So far, I have attempted to code it to allow me to login using credentials in a database on my webhost, and it was good up until this point, tested multiple times. The problem with the code below, when I go to /admin/login.php, and type the credentials I created in the database, it tells me "No such file or directory". Here is the code. Login.php <html><head><title>Sensatus CMS - Admin Area</title></head><body><?phpsession_start();if(isset($_SESSION['user'])) { header("Location: index.php");} else {?><form action="dologin.php" method="post"><table> <tr> <td><span>Username:</span></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><span>Password:</span></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colespan="2" align="right"><input type="submit" name="login" value="Login" /></td> </tr></table></form><?php } ?></body></html> dologin.php <?phpinclude('includes/functions.php');session_start();if(isset($_POST['login'])) { if(isset($_POST['username'])) { if(isset($_POST['password'])) { $username = $_POST['username']; $query = mysql_query ("SELECT * FROM users WHERE Username = '$username'") or die(mysql_error()); $user = mysql_fetch_array($query); if(md5($_POST['password']) == $user['Password']) { echo "Login Successful"; $_SESSION['user'] = $user['Username']; header("Location: index.php"); } else { echo "Please check your login details"; include('login.php'); } } else { echo "Please check your password"; include('login.php'); } } else { echo "Please check your Username"; include('login.php'); }} else { echo "Please check that you filled out the login form!"; include('login.php');}?> and in case it matters, Index.php <html><head><title>Sensatus CMS - Admin Area</title></head><body><?phpsession_start();if(isset($_SESSION['user'])) {?><span>Logged in! Welcome <?php echo $_SESSION['user']; ?></span><?php} else { header("Location: login.php");}?></body></html> Quote Link to comment Share on other sites More sharing options...
laflair13 Posted February 27, 2015 Share Posted February 27, 2015 (edited) "No such file or directory" means that the file is NOT uploaded to the server. I would put the direct url into the address bar to see if it shows up. Without knowing your directory, I am guessing by your code that the file dologin.php is not uploaded to the server or is in the wrong directory. Edited February 27, 2015 by laflair13 Quote Link to comment Share on other sites More sharing options...
brianwilcox Posted February 27, 2015 Author Share Posted February 27, 2015 "No such file or directory" means that the file is NOT uploaded to the server. I would put the direct url into the address bar to see if it shows up. Without knowing your directory, I am guessing by your code that the file dologin.php is not uploaded to the server or is in the wrong directory. That's where I got confused. It is uploaded in the same directory as the login.php. I have checked multiple times. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 27, 2015 Share Posted February 27, 2015 What line is giving you that error? You didn't say. Quote Link to comment Share on other sites More sharing options...
laflair13 Posted February 27, 2015 Share Posted February 27, 2015 (edited) Also keep in mind when you add a / (backslash) to the file path, it will show it coming from the root directory. /admin/login.php Take away the backslash and see if that helps. And like ginerjm asked, the error will show you what line in your code is giving the error. Double check that the file path is correct. I would use a direct file path (http://domain.com/admin/dologin.php) to make sure it is uploaded. Edited February 27, 2015 by laflair13 Quote Link to comment Share on other sites More sharing options...
brianwilcox Posted February 27, 2015 Author Share Posted February 27, 2015 What line is giving you that error? You didn't say. There is no error in the lines at all... No syntax error messages what so ever. Quote Link to comment Share on other sites More sharing options...
laflair13 Posted February 27, 2015 Share Posted February 27, 2015 There is no error in the lines at all... No syntax error messages what so ever. There wouldn't be an error or syntax message, it would be on the frontside of the site. You should see something like this Warning: include_once(dologin.php): failed to open stream: No such file or directory in /home4/username/public_html/domain.com/page.php on line 4 Quote Link to comment Share on other sites More sharing options...
brianwilcox Posted February 27, 2015 Author Share Posted February 27, 2015 There wouldn't be an error or syntax message, it would be on the frontside of the site. You should see something like this Warning: include_once(dologin.php): failed to open stream: No such file or directory in /home4/username/public_html/domain.com/page.php on line 4 Nope. Not seeing anything like that. Quote Link to comment Share on other sites More sharing options...
Sanjib Sinha Posted February 27, 2015 Share Posted February 27, 2015 Please check whether the root path is correctly defined or not. I think there is some problem. Quote Link to comment Share on other sites More sharing options...
JustThatGuy Posted February 27, 2015 Share Posted February 27, 2015 I think you guys are missing the fact that the OP is using PHP wrong. He places session_start(); on every file then includes login.php. The first session is already started on the direct page, but when OP includes the login.php file, the second session_start(); is started which will conflict with the first session. Along with that, you shouldn't be using mysql_* libraries. Switch to mysqli_* or PDO. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 27, 2015 Share Posted February 27, 2015 Not quite correct JustThatGuy. Per the manual - a second session_start call is simply ignored if the session is already begun. Quote Link to comment Share on other sites More sharing options...
JustThatGuy Posted February 27, 2015 Share Posted February 27, 2015 Not quite correct JustThatGuy. Per the manual - a second session_start call is simply ignored if the session is already begun. Another neglect. http://stackoverflow.com/questions/2580322/is-there-any-harm-in-running-session-start-multiple-times-as-the-page-request Try it ourself. Place 2 session_start right after another. You're going to get an internal error. It will not simply get ignored as you say it does. It will throw you an internal errror until you fix it. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 27, 2015 Share Posted February 27, 2015 Yes - it will throw a 'notice' IF you have that turned on (and you should only during development!) - but it will not cause a conflict. I'll trust the manual until otherwise informed. The second call will not begin a 'new' session. And eventually (hopefully) the poster will learn how to better organize his modules and code. 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.