Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , ,

Sponsored Links


PHP Admin Login Error

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 14-04-2009
Member
 
Join Date: Apr 2009
Posts: 425
PHP Admin Login Error

Sponsored Links
i am trying to create an admin user who would be able to manage all users.To start off I have added an extra column admin to my users_table where 1 would indicate an admin user and 0 a normal user. You first take a look in this:-

PHP Code:
<?php # Script 13.1 - header.html
// This page begins the HTML header for the site.

// Start output buffering.
ob_start();
// Initialize a session.
session_start();

// Check for a $page_title value.
if (!isset($page_title)) {
    
$page_title 'Page Title';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title><?php echo $page_title?></title>
<style type="text/css" media="screen">@import "./includes/layout.css";</style>
</head>
<body>
<div id="Header">Page Title</div>
<div id="Content">
<!-- End of Header -->
<!-- End of Content -->
</div>
<div id="Menu">
<a href="index.php">Home</a>&nbsp;&nbsp; |
<?php # Script 13.2 - footer.html
// This page completes the HTML template.

// Display links based upon the login status.
// Show LOGIN links if this is the LOGOUT page.
if (isset($_SESSION['user_id']) && (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) {
    echo 
'<a href="logout.php">Logout</a> &nbsp;&nbsp; |
<a href="change_password.php">Change Password</a> &nbsp;&nbsp; |
<a href="diary.php">Availability</a>&nbsp;&nbsp; |
<a href="account.php">My Account</a>&nbsp;&nbsp; |
'
;
} else { 
//  Not logged in.
    
echo '    <a href="register.php">Register</a>&nbsp;&nbsp; |
<a href="login.php">Login</a>&nbsp;&nbsp; |
<a href="forgot_password.php">Forgot Password</a>&nbsp;&nbsp; |
'
;
}
?>
<a href="#">Some Page</a>&nbsp;&nbsp; |
<a href="#">Another Page</a>
</div>
</body>
</html>
I recognise the area where I need to make a change:
PHP Code:
// Show LOGIN links if this is the LOGOUT page.
if (isset($_SESSION['user_id']) && (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) { 
and I have changed to this:

PHP Code:
// Show LOGIN links if this is the LOGOUT page.
if (isset($_SESSION['user_id']) && $_SESSION['admin'] != 0) && (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) { 
so that I can define different links if an admin has logged in, otherwise normal links for user, or if not logged in then some other links.But this gives me the following error:

Parse error: syntax error, unexpected T_BOOLEAN_AND in line 35.

Why is that so? Could you all guys tell me where i am wrong and what should i do to make it correct ?

Reply With Quote
  #2  
Old 14-04-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,991
Re: PHP Admin Login Error

Problem is on line 35. You closed the if(...) too early so when PHP found the && it got confused.

Make it like this and hope you won't get error:-

PHP Code:
if (isset($_SESSION['user_id']) && $_SESSION['admin'] != && substr($_SERVER['PHP_SELF'], -10) != 'logout.php') {
    echo <
a href="logout.php">Logout</a> &nbsp;&nbsp; | 
Reply With Quote
  #3  
Old 14-04-2009
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,278
Re: PHP Admin Login Error

I would recommend something like Notepad++ for your PHP code, if you require a minimalistic feature full PHP editor or Eclipse PDT which has even a lot more.

Because both of them have a so called "bracket match" capability which shows you exactly where you might have omitted your opening or closing brackets. That would have solved your problem right from the beginning and you would have time to spare on some other things more interesting from an omitted bracket.
Reply With Quote
  #4  
Old 14-04-2009
Member
 
Join Date: Apr 2009
Posts: 425
Re: PHP Admin Login Error

Thanks for all your help. I have made that amendments and no error comes up now.

Thanks once again !
Reply With Quote
  #5  
Old 24-05-2011
Member
 
Join Date: May 2011
Posts: 1
Re: Can't access index.php

Hi guy's, im new in php coding,. and i am having some problems logging in.
i can access admin_login.php but after i login and press login button it redirect it to admin_login.php again where its supposed to be directing to index.php.

PHP Code:
<?php 
session_start
();
if (!isset(
$_SESSION["manager"])) {
    
header("location: index.php"); 
    exit();
}
?>
<?php 

if (isset($_POST["username"]) && isset($_POST["password"])) {

    
$manager preg_replace('#[^A-Za-z0-9]#i'''$_POST["username"]); 
    
$password preg_replace('#[^A-Za-z0-9]#i'''$_POST["password"]);
    include 
"../sdtscripts/connect_to_mysql.php"
    
$sql mysql_query("SELECT id FROM users WHERE username='$manager' AND password='$password' LIMIT 1"); 
    
$existCount mysql_num_rows($sql); 
    if (
$existCount == 1) { 
         while(
$row mysql_fetch_array($sql)){ 
             
$id $row["id"];
         }
         
$_SESSION["id"] = $id;
         
$_SESSION["manager"] = $manager;
         
$_SESSION["password"] = $password;
         
header("location: index.php");
         exit();
    } else {
        echo 
'That information is incorrect, try again <a href="index.php">Click Here</a>';
        exit();
    }
}
?>
Can anyone help me with this.

Thanks.
Reply With Quote
  #6  
Old 25-05-2011
Member
 
Join Date: Jan 2006
Posts: 605
Re: PHP Admin Login Error

Hi sjb_jparedes,

First of all, are you connecting to your db and have you tried echoing the number of rows to make sure you are grabbing any. Have you also tried to debug your query yet. eg

PHP Code:
$sql mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1") or die(mysql_error()); 
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "PHP Admin Login Error"
Thread Thread Starter Forum Replies Last Post
Battlefield 3 installation asking for admin login aNaHiTa$ Video Games 2 30-10-2011 06:39 AM
Opera Unite Admin 404 Error VAIL Technology & Internet 5 20-06-2011 07:52 PM
Every user needs admin to login them into Acrobat 9 Madhuparna Windows Software 6 17-07-2010 12:04 AM
Non-admin users fail login with System Event Notification Service failure John B Vista Help 7 10-07-2009 08:20 PM
Add users to local admin via login script Allanoo Active Directory 3 26-04-2006 09:59 PM


All times are GMT +5.5. The time now is 07:55 PM.