Jump to content

Admin check


DizzyThermal

Recommended Posts

Hey guys, I've set up a database with a login and logout script for my site..

 

There is a TINYINT value called admin and it either equals 1 or 0 depending on whether the user is an admin or not..

 

The registration script works perfectly to create the table value and the login script works fine for the site..

 

The question I had was if I wanted to add a link to the bottom of every page that said:

 

Go to Administration Panel and make it only viewable by ADMINS I figured this little script would work..

 

 

Here would be the end of the page:

  <br />
  <center>Copyright &copy 2010 <a href="http://www.website.com">www.WEBSITE.com</a></center>

  <?php include('includes/start_admincheck.php'); ?>
    <center><a href="<?php echo $homedir .'admin.php'; ?>">Go to Administration Panel</a></center>
  <?php include('includes/end_admincheck.php'); ?>

</body>

</html>

 

Inside start_admincheck.php I have:

 

(NOTE: $cUsername refers to a setcookie and $cAdmin does as well.. They are defined on my Variable page included at the top.)

<?php include('variables/variables.php'); ?>

<?php
  mysql_connect("$mysql_hostname", "$mysql_username", "$mysql_password") or die(mysql_error());
  mysql_select_db("$mysql_database") or die(mysql_error());

  if(isset($cUsername))
  {
    $check = mysql_query("SELECT * FROM users WHERE username = '$cUsername'")or die(mysql_error());

    while($info = mysql_fetch_array( $check ))
    {
      if (($cAdmin == 1) && ($info['admin'] == 1))
      {
?>

 

And this is the end_admincheck.php

<?php include('variables/variables.php'); ?>

<?php
      }

      else
        die(); 
    } 
  }
  else
    die();
?>
?>

 

I get this Parse error thrown at the bottom of the page:

 

Parse error: syntax error, unexpected $end in /*******/includes/start_admincheck.php on line 15

 

Naturally I would checkout line 15 in start_admincheck.php, but normally when I get an $end error it is the last line of the code and leaves me lost..

 

Something I'm missing guys?

 

As always, thanks in advance  ;)

Link to comment
Share on other sites

I don't think it's possible to just end php ?> without closing if/while tags.. then again I've never tried that. But that seems to be the error your getting here.

 

It's obvious you are trying to keep your html and php seperate but with this particular code, I don't know that u have a choice.

Link to comment
Share on other sites

if you don't have a lot of PHP code on your footer area or the entire page (depending how you created it) it might be better to just clean it up.

 

footer area:

  <br />
  <center>Copyright &copy 2010 <a href="http://www.website.com">www.WEBSITE.com</a></center>

  <?php include('includes/start_admincheck.php'); ?>

</body>

</html>

 

start_admincheck.php:

<?php include('variables/variables.php'); ?>

<?php
  mysql_connect("$mysql_hostname", "$mysql_username", "$mysql_password") or die(mysql_error());
  mysql_select_db("$mysql_database") or die(mysql_error());

  if(isset($cUsername))
  {
    $check = mysql_query("SELECT * FROM users WHERE username = '$cUsername'")or die(mysql_error());

    while($info = mysql_fetch_array( $check ))
    {
      if (($cAdmin == 1) && ($info['admin'] == 1))
      {
          echo "<center><a href=\"<?php echo $homedir .'admin.php'; ?>\">Go to Administration Panel</a></center>";
      }

      else
        die(); 
    } 
  }
  else
    die();
?>

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.