Jump to content

Admin Login Page Help


brianwilcox

Recommended Posts

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>
<?php
session_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

 

<?php
include('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>
<?php
session_start();
if(isset($_SESSION['user'])) {
?>
<span>Logged in! Welcome <?php echo $_SESSION['user']; ?></span>
<?php
} else {
    header("Location: login.php");
}
?>
</body>
</html>

 

Link to comment
Share on other sites

"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 by laflair13
Link to comment
Share on other sites

"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.

Link to comment
Share on other sites

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 by laflair13
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.