Avatar billede DePlex Nybegynder
14. juni 2010 - 16:34 Der er 25 kommentarer og
1 løsning

Parse error

Det er denne kode der giver fejlen... Kan i se hvad fejlen er?

(!$session->isAdmin())
  header("Location: ../main.php");
}
else{

Der står: Parse error: syntax error, unexpected T_STRING in /home/vhosts/christianhost.eu5.org/admin.php  on line 85

Hvis man bruger denne kode:

(!$session->isAdmin()){
  header("Location: ../main.php");
}
else{

Får man:

Parse error: syntax error, unexpected '{' in /home/vhosts/christianhost.eu5.org/admin.php  on line 84

Nogle der kan hjælpe mig?
Avatar billede intenz Novice
14. juni 2010 - 16:57 #1
En if/else ser sådan ud (i den helt basale udgave).

if (...noget...) {
  ...noget kode
} else {
  ...noget andet kode
}
Avatar billede DePlex Nybegynder
14. juni 2010 - 17:01 #2
Hvis man tager if foran kommer der:

Fatal error: Call to a member function isAdmin() on a non-object in /home/vhosts/christianhost.eu5.org/admin.php on line 84
Avatar billede intenz Novice
14. juni 2010 - 17:15 #3
Det er fordi funktionen isAdmin() ikke eksisterer i $session. Du er sikker på du ikke mener $session->isAdmin ? Altså uden ().
Avatar billede DePlex Nybegynder
14. juni 2010 - 17:55 #4
Nu er der bare det problem at nu gider den ikke at give mig adgang til admin.php... Den sender mig bare tilbage til forsiden, som den skulle gøre ved folk der ikke er admin. Nogle der har en ide hvorfor?
Avatar billede dkfire Nybegynder
14. juni 2010 - 23:29 #5
Vi kan kun hjælpe dig hvis du viser noget mere kode.
Ud fra hvad du har vist kan ingen give dig et kvalificeret bud.

Vis din klasse samt hvordan du bruger den.
Avatar billede DePlex Nybegynder
15. juni 2010 - 19:23 #6
function isAdmin{
      return ($this->userlevel == ADMIN_LEVEL
              $this->username  == ADMIN_NAME);
Avatar billede dkfire Nybegynder
18. juni 2010 - 10:09 #7
Du har jo heller ikke lavet din funktion rigtig.
Tror du bør læse lidt mere om PHP og programmering før du begiver dig videre.

Din funktion bør mindst være:
function isAdmin(){
      return ($this->userlevel == ADMIN_LEVEL &&
              $this->username  == ADMIN_NAME)? TRUE : FALSE;


Men hvis du viser lidt mere af din kode kan det være jeg kan hjælpe dig videre.
Jeg bliver nød til at se hele din klasse og hele den side hvor du prøver at bruge klassen.
Avatar billede dkfire Nybegynder
18. juni 2010 - 10:10 #8
Og så manglede jeg endda noget kode.

function isAdmin(){
      return ($this->userlevel == ADMIN_LEVEL &&
              $this->username  == ADMIN_NAME)? TRUE : FALSE;
}
Avatar billede DePlex Nybegynder
19. juni 2010 - 20:50 #9
if(!$session->isAdmin){
  header("Location: ../main.php");
}
else{

Det er det der står i admin.php
Avatar billede dkfire Nybegynder
20. juni 2010 - 10:23 #10
Det er helt i orden hvis du vil vise hele din kode, men så kan jeg heller ikke hjælpe dig videre.

Du bliver nød til at vise HELE din kode, både for klassen samt admin.php
Avatar billede DePlex Nybegynder
20. juni 2010 - 11:53 #11
admin.php:

<?php
include("../include/session.php");
?>

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Jpmaster77's Login Script</title>
<link rel="stylesheet" href="../-css/960/reset.css" type="text/css" />
<link rel="stylesheet" href="../-css/960/960.css" type="text/css" />
<link rel="stylesheet" href="../-css/960/text.css" type="text/css" />
<link rel="stylesheet" href="../-css/style.css" type="text/css" />
</head>
<body>

<?php
/**
* displayUsers - Displays the users database table in
* a nicely formatted html table.
*/
function displayUsers(){
  global $database;
  $q = "SELECT username,userlevel,email,timestamp "
      ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
  $result = $database->query($q);
  /* Error occurred, return given name by default */
  $num_rows = mysql_numrows($result);
  if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
  }
  if($num_rows == 0){
      echo "Database table empty";
      return;
  }
  /* Display table contents */
  echo "<table id='display'>";
  echo "<tr class='title'><td colspan='2'>Username</td><td>Level</td><td colspan='2'>Email</td><td colspan='2'>Last Active</td></tr>";
  echo "<div class='clear'></div>";
  for($i=0; $i<$num_rows; $i++){
      $uname = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email = mysql_result($result,$i,"email");
      $time = mysql_result($result,$i,"timestamp");

      echo "<tr><td colspan='2'>".$uname."</td><td>".$ulevel."</td><td colspan='2'>".$email."</td><td colspan='2'>".$time."</td></tr>";
  }
  echo "</table>";
}

/**
* displayBannedUsers - Displays the banned users
* database table in a nicely formatted html table.
*/
function displayBannedUsers(){
  global $database;
  $q = "SELECT username,timestamp "
      ."FROM ".TBL_BANNED_USERS." ORDER BY username";
  $result = $database->query($q);
  /* Error occurred, return given name by default */
  $num_rows = mysql_numrows($result);
  if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
  }
  if($num_rows == 0){
      echo "<p class='grid_12'>Database table empty</p>";
      return;
  }
  /* Display table contents */
  echo "<table id='display'>";
  echo "<tr class='title'><tr colspan='2'>Username</td><td colspan='2'>Time Banned</td></tr>";
  for($i=0; $i<$num_rows; $i++){
      $uname = mysql_result($result,$i,"username");
      $time = mysql_result($result,$i,"timestamp");

      echo "<tr><td colspan='2'>".$uname."</td><td colspan='2'>".$time."</td></tr>";
  }
  echo "</table>";
}
 
/**
* User not an administrator, redirect to main page
* automatically.
*/
if(!$session->isAdmin){
  header("Location: ../main.php");
}
else{
/**
* Administrator is viewing page, so display all
* forms.
*/
?>
<html>
<title>Jpmaster77's Login Script</title>
<body>
<div id="main" class="container_12">

<h1>Admin Center</h1>
<font size="5" color="#ff0000">
<b>::::::::::::::::::::::::::::::::::::::::::::</b></font>
<font size="4">Logged in as <b><?php echo $session->username; ?></b></font><br><br>
Back to [<a href="../main.php">Main Page</a>]<br><br>
<?php
if($form->num_errors > 0){
  echo "<font size=\"4\" color=\"#ff0000\">"
      ."!*** Error with request, please fix</font><br><br>";
}

/**
* Display Users Table
*/
?>
<h3>Users Table Contents:</h3>
<?php
displayUsers();
?>
<hr>
<?php
/**
* Update User Level
*/
?>
<div class="update">
<h3>Update User Level</h3>
<?php echo $form->error("upduser"); ?>
<form action="adminprocess.php" method="POST">
<p class="grid_4">Username: <input type="text" name="upduser" maxlength="30" value="<?php echo $form->value("upduser"); ?>"></p>
<p class="grid_2">Level:
<select name="updlevel">
<option value="1">1</option>
<option value="5">5</option>
<option value="9">9</option>
</select>
</p>
<input type="hidden" name="subupdlevel" value="1">
<input type="submit" value="Update Level">
</form>
</div>
<hr>
<?php
/**
* Delete User
*/
?>
<div class="update">
<h3>Delete User</h3>
<?php echo $form->error("deluser"); ?>
<form action="adminprocess.php" method="POST">
<p class="grid_4">Username: <input type="text" name="deluser" maxlength="30" value="<?php echo $form->value("deluser"); ?>"></p>
<input type="hidden" name="subdeluser" value="1">
<input type="submit" value="Delete User">
</form>
</div>
<hr>
<?php
/**
* Delete Inactive Users
*/
?>
<div class="update">
<h3>Delete Inactive Users</h3>
This will delete all users (not administrators), who have not logged in to the site<br>
within a certain time period. You specify the days spent inactive.<br><br>
<form action="adminprocess.php" method="POST">
<p class="grid_2">Days: <select name="inactdays">
<option value="3">3</option>
<option value="7">7</option>
<option value="14">14</option>
<option value="30">30</option>
<option value="100">100</option>
<option value="365">365</option>
</select>
</p>
<input type="hidden" name="subdelinact" value="1">
<input type="submit" value="Delete All Inactive">
</form>
</div>
<hr>
<?php
/**
* Ban User
*/
?>
<div class="update">
<h3>Ban User</h3><?php echo $form->error("banuser"); ?>
<form action="adminprocess.php" method="POST">
<p class="grid_4">Username: <input type="text" name="banuser" maxlength="30" value="<?php echo $form->value("banuser"); ?>"></p>
<input type="hidden" name="subbanuser" value="1">
<input type="submit" value="Ban User">
</form>
</div>
<hr>
<?php
/**
* Display Banned Users Table
*/
?>
<h3>Banned Users Table Contents:</h3>
<?php
displayBannedUsers();
?>
<hr>
<?php
/**
* Delete Banned User
*/
?>
<div class="update">
<h3>Delete Banned User</h3><?php echo $form->error("delbanuser"); ?>
<form action="adminprocess.php" method="POST">
<p class="grid_4">Username: <input type="text" name="delbanuser" maxlength="30" value="<?php echo $form->value("delbanuser"); ?>"></p>
<input type="hidden" name="subdelbanned" value="1">
<input type="submit" value="Delete Banned User">
</form>
</div>

<hr>

Back to [<a href="../main.php">Main Page</a>]<br><br>


</div>
</body>
</html>
<?php
}
?>











session.php:

<?php
/**
* Session.php
*
* The Session class is meant to simplify the task of keeping
* track of logged in users and also guests.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 2, 2009 by Ivan Novak
*/
include("database.php");
include("mailer.php");
include("form.php");

class Session
{
  var $username; //Username given on sign-up
  var $userid; //Random value generated on current login
  var $userlevel; //The level to which the user pertains
  var $time; //Time user was last active (page loaded)
  var $logged_in; //True if user is logged in, false otherwise
  var $userinfo = array(); //The array holding all user info
  var $url; //The page url current being viewed
  var $referrer; //Last recorded site page viewed
  /**
* Note: referrer should really only be considered the actual
* page referrer in process.php, any other time it may be
* inaccurate.
*/

  /* Class constructor */
  function Session(){
      $this->time = time();
      $this->startSession();
  }

  /**
* startSession - Performs all the actions necessary to
* initialize this session object. Tries to determine if the
* the user has logged in already, and sets the variables
* accordingly. Also takes advantage of this page load to
* update the active visitors tables.
*/
  function startSession(){
      global $database; //The database connection
      session_start(); //Tell PHP to start the session

      /* Determine if user is logged in */
      $this->logged_in = $this->checkLogin();

      /**
* Set guest value to users not logged in, and update
* active guests table accordingly.
*/
      if(!$this->logged_in){
        $this->username = $_SESSION['username'] = GUEST_NAME;
        $this->userlevel = GUEST_LEVEL;
        $database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
      }
      /* Update users last active timestamp */
      else{
        $database->addActiveUser($this->username, $this->time);
      }
     
      /* Remove inactive visitors from database */
      $database->removeInactiveUsers();
      $database->removeInactiveGuests();
     
      /* Set referrer page */
      if(isset($_SESSION['url'])){
        $this->referrer = $_SESSION['url'];
      }else{
        $this->referrer = "/";
      }

      /* Set current url */
      $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
  }

  /**
* checkLogin - Checks if the user has already previously
* logged in, and a session with the user has already been
* established. Also checks to see if user has been remembered.
* If so, the database is queried to make sure of the user's
* authenticity. Returns true if the user has logged in.
*/
  function checkLogin(){
      global $database; //The database connection
      /* Check if user has been remembered */
      if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){
        $this->username = $_SESSION['username'] = $_COOKIE['cookname'];
        $this->userid = $_SESSION['userid'] = $_COOKIE['cookid'];
      }

      /* Username and userid have been set and not guest */
      if(isset($_SESSION['username']) && isset($_SESSION['userid']) &&
        $_SESSION['username'] != GUEST_NAME){
        /* Confirm that username and userid are valid */
        if($database->confirmUserID($_SESSION['username'], $_SESSION['userid']) != 0){
            /* Variables are incorrect, user not logged in */
            unset($_SESSION['username']);
            unset($_SESSION['userid']);
            return false;
        }

        /* User is logged in, set class variables */
        $this->userinfo = $database->getUserInfo($_SESSION['username']);
        $this->username = $this->userinfo['username'];
        $this->userid = $this->userinfo['userid'];
        $this->userlevel = $this->userinfo['userlevel'];
        return true;
      }
      /* User not logged in */
      else{
        return false;
      }
  }

  /**
* login - The user has submitted his username and password
* through the login form, this function checks the authenticity
* of that information in the database and creates the session.
* Effectively logging in the user if all goes well.
*/
  function login($subuser, $subpass, $subremember){
      global $database, $form; //The database and form object

      /* Username error checking */
      $field = "user"; //Use field name for username
$q = "SELECT valid FROM ".TBL_USERS." WHERE username='$subuser'";
$valid = $database->query($q);
$valid = mysql_fetch_array($valid);

      if(!$subuser || strlen($subuser = trim($subuser)) == 0){
        $form->setError($field, "* Username not entered");
      }
      else{
        /* Check if username is not alphanumeric */
        if(!eregi("^([0-9a-z])*$", $subuser)){
            $form->setError($field, "* Username not alphanumeric");
        }
      }

      /* Password error checking */
      $field = "pass"; //Use field name for password
      if(!$subpass){
        $form->setError($field, "* Password not entered");
      }
     
      /* Return if form errors exist */
      if($form->num_errors > 0){
        return false;
      }

      /* Checks that username is in database and password is correct */
      $subuser = stripslashes($subuser);
      $result = $database->confirmUserPass($subuser, md5($subpass));

      /* Check error codes */
      if($result == 1){
        $field = "user";
        $form->setError($field, "* Username not found");
      }
      else if($result == 2){
        $field = "pass";
        $form->setError($field, "* Invalid password");
      }
     
      /* Return if form errors exist */
      if($form->num_errors > 0){
        return false;
      }

     
      if(EMAIL_WELCOME){
      if($valid['valid'] == 0){
      $form->setError($field, "* User's account has not yet been confirmed.");
      }
      }
                 
      /* Return if form errors exist */
      if($form->num_errors > 0){
        return false;
      }
     


      /* Username and password correct, register session variables */
      $this->userinfo = $database->getUserInfo($subuser);
      $this->username = $_SESSION['username'] = $this->userinfo['username'];
      $this->userid = $_SESSION['userid'] = $this->generateRandID();
      $this->userlevel = $this->userinfo['userlevel'];
     
      /* Insert userid into database and update active users table */
      $database->updateUserField($this->username, "userid", $this->userid);
      $database->addActiveUser($this->username, $this->time);
      $database->removeActiveGuest($_SERVER['REMOTE_ADDR']);

      /**
* This is the cool part: the user has requested that we remember that
* he's logged in, so we set two cookies. One to hold his username,
* and one to hold his random value userid. It expires by the time
* specified in constants.php. Now, next time he comes to our site, we will
* log him in automatically, but only if he didn't log out before he left.
*/
      if($subremember){
        setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
        setcookie("cookid", $this->userid, time()+COOKIE_EXPIRE, COOKIE_PATH);
      }

      /* Login completed successfully */
      return true;
  }

  /**
* logout - Gets called when the user wants to be logged out of the
* website. It deletes any cookies that were stored on the users
* computer as a result of him wanting to be remembered, and also
* unsets session variables and demotes his user level to guest.
*/
  function logout(){
      global $database; //The database connection
      /**
* Delete cookies - the time must be in the past,
* so just negate what you added when creating the
* cookie.
*/
      if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){
        setcookie("cookname", "", time()-COOKIE_EXPIRE, COOKIE_PATH);
        setcookie("cookid", "", time()-COOKIE_EXPIRE, COOKIE_PATH);
      }

      /* Unset PHP session variables */
      unset($_SESSION['username']);
      unset($_SESSION['userid']);

      /* Reflect fact that user has logged out */
      $this->logged_in = false;
     
      /**
* Remove from active users table and add to
* active guests tables.
*/
      $database->removeActiveUser($this->username);
      $database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
     
      /* Set user level to guest */
      $this->username = GUEST_NAME;
      $this->userlevel = GUEST_LEVEL;
  }

  /**
* register - Gets called when the user has just submitted the
* registration form. Determines if there were any errors with
* the entry fields, if so, it records the errors and returns
* 1. If no errors were found, it registers the new user and
* returns 0. Returns 2 if registration failed.
*/
  function register($subuser, $subpass, $subemail, $subname){
      global $database, $form, $mailer; //The database, form and mailer object
     
      /* Username error checking */
      $field = "user"; //Use field name for username
      if(!$subuser || strlen($subuser = trim($subuser)) == 0){
        $form->setError($field, "* Username not entered");
      }
      else{
        /* Spruce up username, check length */
        $subuser = stripslashes($subuser);
        if(strlen($subuser) < 5){
            $form->setError($field, "* Username below 5 characters");
        }
        else if(strlen($subuser) > 30){
            $form->setError($field, "* Username above 30 characters");
        }
        /* Check if username is not alphanumeric */
        else if(!eregi("^([0-9a-z])+$", $subuser)){
            $form->setError($field, "* Username not alphanumeric");
        }
        /* Check if username is reserved */
        else if(strcasecmp($subuser, GUEST_NAME) == 0){
            $form->setError($field, "* Username reserved word");
        }
        /* Check if username is already in use */
        else if($database->usernameTaken($subuser)){
            $form->setError($field, "* Username already in use");
        }
        /* Check if username is banned */
        else if($database->usernameBanned($subuser)){
            $form->setError($field, "* Username banned");
        }
      }

      /* Password error checking */
      $field = "pass"; //Use field name for password
      if(!$subpass){
        $form->setError($field, "* Password not entered");
      }
      else{
        /* Spruce up password and check length*/
        $subpass = stripslashes($subpass);
        if(strlen($subpass) < 4){
            $form->setError($field, "* Password too short");
        }
        /* Check if password is not alphanumeric */
        else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){
            $form->setError($field, "* Password not alphanumeric");
        }
        /**
* Note: I trimmed the password only after I checked the length
* because if you fill the password field up with spaces
* it looks like a lot more characters than 4, so it looks
* kind of stupid to report "password too short".
*/
      }
     
      /* Email error checking */
      $field = "email"; //Use field name for email
      if(!$subemail || strlen($subemail = trim($subemail)) == 0){
        $form->setError($field, "* Email not entered");
      }
      else{
        /* Check if valid email address */
        $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
                ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
                ."\.([a-z]{2,}){1}$";
        if(!eregi($regex,$subemail)){
            $form->setError($field, "* Email invalid");
        }
        /* Check if email is already in use */
        if($database->emailTaken($subemail)){
            $form->setError($field, "* Email already in use");
        }

        $subemail = stripslashes($subemail);
      }
     
      /* Name error checking */
$field = "name";
if(!$subname || strlen($subname = trim($subname)) == 0){
$form->setError($field, "* Name not entered");
} else {
$subname = stripslashes($subname);
}
     
      $randid = $this->generateRandID();
     
      /* Errors exist, have user correct them */
      if($form->num_errors > 0){
        return 1; //Errors with form
      }
      /* No errors, add the new account to the */
      else{
        if($database->addNewUser($subuser, md5($subpass), $subemail, $randid, $subname)){
            if(EMAIL_WELCOME){
              $mailer->sendWelcome($subuser,$subemail,$subpass,$randid);
            }
            return 0; //New user added succesfully
        }else{
            return 2; //Registration attempt failed
        }
      }
  }
 
  /**
* editAccount - Attempts to edit the user's account information
* including the password, which it first makes sure is correct
* if entered, if so and the new password is in the right
* format, the change is made. All other fields are changed
* automatically.
*/
  function editAccount($subcurpass, $subnewpass, $subemail, $subname){
      global $database, $form; //The database and form object
      /* New password entered */
      if($subnewpass){
        /* Current Password error checking */
        $field = "curpass"; //Use field name for current password
        if(!$subcurpass){
            $form->setError($field, "* Current Password not entered");
        }
        else{
            /* Check if password too short or is not alphanumeric */
            $subcurpass = stripslashes($subcurpass);
            if(strlen($subcurpass) < 4 ||
              !eregi("^([0-9a-z])+$", ($subcurpass = trim($subcurpass)))){
              $form->setError($field, "* Current Password incorrect");
            }
            /* Password entered is incorrect */
            if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){
              $form->setError($field, "* Current Password incorrect");
            }
        }
       
        /* New Password error checking */
        $field = "newpass"; //Use field name for new password
        /* Spruce up password and check length*/
        $subpass = stripslashes($subnewpass);
        if(strlen($subnewpass) < 4){
            $form->setError($field, "* New Password too short");
        }
        /* Check if password is not alphanumeric */
        else if(!eregi("^([0-9a-z])+$", ($subnewpass = trim($subnewpass)))){
            $form->setError($field, "* New Password not alphanumeric");
        }
      }
      /* Change password attempted */
      else if($subcurpass){
        /* New Password error reporting */
        $field = "newpass"; //Use field name for new password
        $form->setError($field, "* New Password not entered");
      }
     
      /* Email error checking */
      $field = "email"; //Use field name for email
      if($subemail && strlen($subemail = trim($subemail)) > 0){
        /* Check if valid email address */
        $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
                ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
                ."\.([a-z]{2,}){1}$";
        if(!eregi($regex,$subemail)){
            $form->setError($field, "* Email invalid");
        }
        $subemail = stripslashes($subemail);
      }
     
      /* Name error checking */
$field = "name";
if(!$subname || strlen($subname = trim($subname)) == 0){
$form->setError($field, "* Name not entered");
} else {
$subname = stripslashes($subname);
}
     
      /* Errors exist, have user correct them */
      if($form->num_errors > 0){
        return false; //Errors with form
      }
     
      /* Update password since there were no errors */
      if($subcurpass && $subnewpass){
        $database->updateUserField($this->username,"password",md5($subnewpass));
      }
     
      /* Change Email */
      if($subemail){
        $database->updateUserField($this->username,"email",$subemail);
      }
     
      /* Change Name */
      if($subname){
        $database->updateUserField($this->username,"name",$subname);
      }
     
      /* Success! */
      return true;
  }
 
  /**
* isAdmin - Returns true if currently logged in user is
* an administrator, false otherwise.
*/
function isAdmin{
      return ($this->userlevel == ADMIN_LEVEL &&
              $this->username  == ADMIN_NAME)? TRUE : FALSE;
}
  }
 
  /**
* isAuthor - Returns true if currently logged in user is
* an author or an administrator, false otherwise.
*/
  function isAuthor(){
      return ($this->userlevel == AUTHOR_LEVEL ||
              $this->userlevel == ADMIN_LEVEL);
  }
 
  /**
* generateRandID - Generates a string made up of randomized
* letters (lower and upper case) and digits and returns
* the md5 hash of it to be used as a userid.
*/
  function generateRandID(){
      return md5($this->generateRandStr(16));
  }
 
  /**
* generateRandStr - Generates a string made up of randomized
* letters (lower and upper case) and digits, the length
* is a specified parameter.
*/
  function generateRandStr($length){
      $randstr = "";
      for($i=0; $i<$length; $i++){
        $randnum = mt_rand(0,61);
        if($randnum < 10){
            $randstr .= chr($randnum+48);
        }else if($randnum < 36){
            $randstr .= chr($randnum+55);
        }else{
            $randstr .= chr($randnum+61);
        }
      }
      return $randstr;
  }
};


/**
* Initialize session object - This must be initialized before
* the form object because the form uses session variables,
* which cannot be accessed unless the session has started.
*/
$session = new Session;

/* Initialize form object */
$form = new Form;

?>
Avatar billede dkfire Nybegynder
23. juni 2010 - 22:08 #12
Jeg har forsøg at rette lidt i din kode:
admin.php
http://pastebin.com/RnjXrC94

session.php:
http://pastebin.com/gxBH6fvd


Dog bør du nok opdatere kode lidt, der er ALT for mange gamle html tags i den. Og så bør du nok prøve at læse koden igennem og se hvad den egentlig gør, da jeg tvivler meget på du selv har lavet den.

Sig til hvis det giver flere problemer.
Avatar billede DePlex Nybegynder
24. juni 2010 - 14:38 #13
Nu giver den denne fejl på forsiden: Fatal error: Call to a member function value() on a non-object in /home/vhosts/christianhost.eu5.org/main.php on line 57


Her er forsiden:

<?
/**
* Main.php
*
* This is an example of the main page of a website. Here
* users will be able to login. However, like on most sites
* the login form doesn't just have to be on the main page,
* but re-appear on subsequent pages, depending on whether
* the user has logged in or not.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 26, 2004
*/
include("include/session.php");
?>

<html>
<title>Jpmaster77's Login Script</title>
<body>

<table>
<tr><td>


<?
/**
* User has already logged in, so display relavent links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
  echo "<h1>Logged In</h1>";
  echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
      ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
      ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
  if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
  }
  echo "[<a href=\"process.php\">Logout</a>]";
}
else{
?>

<h1>Login</h1>
<?
/**
* User not logged in, display the login form.
* If user has already tried to login, but errors were
* found, display the total number of errors.
* If errors occurred, they will be displayed.
*/
if($form->num_errors > 0){
  echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
<tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr>
</table>
</form>

<?
}

/**
* Just a little page footer, tells how many registered members
* there are, how many users currently logged in and viewing site,
* and how many guests viewing site. Active users are displayed,
* with link to their user information.
*/
echo "</td></tr><tr><td align=\"center\"><br><br>";
echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
echo "There are $database->num_active_users registered members and ";
echo "$database->num_active_guests guests viewing the site.<br><br>";

include("include/view_active.php");

?>


</td></tr>
</table>


</body>
</html>
Avatar billede dkfire Nybegynder
24. juni 2010 - 19:04 #14
Og linje 57 er ??

Er $form lavet rigtigt ?? D.v.s. er det et objekt af den rigtige klasse ?
Avatar billede DePlex Nybegynder
26. juni 2010 - 21:06 #15
Linje 57 er: <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
Avatar billede dkfire Nybegynder
27. juni 2010 - 12:10 #16
Og du er sikker på $form er et objekt af klassen Form ?? og at din klasse har en metode ( funktion ) som hedder value ?

Prøv at lave en vardump($form) eller print_r($form) inden du bruger $form første gang.
Avatar billede DePlex Nybegynder
27. juni 2010 - 16:04 #17
Jeg er nybegynder til php. Det er derfor det hele er downloaded. Jeg bruger det til at arbejde vidre med, men først når det virker. Så derfor ved jeg ikke hvad du mener. Men jeg har været inde i min fil form.php og der kan jeg ikke finde noget. Her har du filensindhold:

<?
/**
* Form.php
*
* The Form class is meant to simplify the task of keeping
* track of errors in user submitted forms and the form
* field values that were entered correctly.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 19, 2004
*/

class Form
{
  var $values = array();  //Holds submitted form field values
  var $errors = array();  //Holds submitted form error messages
  var $num_errors;  //The number of errors in submitted form

  /* Class constructor */
  function Form(){
      /**
      * Get form value and error arrays, used when there
      * is an error with a user-submitted form.
      */
      if(isset($_SESSION['value_array']) && isset($_SESSION['error_array'])){
        $this->values = $_SESSION['value_array'];
        $this->errors = $_SESSION['error_array'];
        $this->num_errors = count($this->errors);

        unset($_SESSION['value_array']);
        unset($_SESSION['error_array']);
      }
      else{
        $this->num_errors = 0;
      }
  }

  /**
    * setValue - Records the value typed into the given
    * form field by the user.
    */
  function setValue($field, $value){
      $this->values[$field] = $value;
  }

  /**
    * setError - Records new form error given the form
    * field name and the error message attached to it.
    */
  function setError($field, $errmsg){
      $this->errors[$field] = $errmsg;
      $this->num_errors = count($this->errors);
  }

  /**
    * value - Returns the value attached to the given
    * field, if none exists, the empty string is returned.
    */
  function value($field){
      if(array_key_exists($field,$this->values)){
        return htmlspecialchars(stripslashes($this->values[$field]));
      }else{
        return "";
      }
  }

  /**
    * error - Returns the error message attached to the
    * given field, if none exists, the empty string is returned.
    */
  function error($field){
      if(array_key_exists($field,$this->errors)){
        return "<font size=\"2\" color=\"#ff0000\">".$this->errors[$field]."</font>";
      }else{
        return "";
      }
  }

  /* getErrorArray - Returns the array of error messages */
  function getErrorArray(){
      return $this->errors;
  }
};

?>
Avatar billede dkfire Nybegynder
27. juni 2010 - 19:22 #18
Når du nu har valgt at have et script som er baseret på klasser, så bør du som minimum læse lidt om klasser, objekter og objekt orienteret programmering.

Men hvad giver "echo vardump($form);" dig ?
Avatar billede DePlex Nybegynder
27. juni 2010 - 20:09 #19
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/vhosts/christianhost.eu5.org/main.php  on line 57
Avatar billede dkfire Nybegynder
27. juni 2010 - 20:40 #20
Uden kode giver det ingen mening, udover du sikkert ikke lige har brugt 2 minutter på at tænke over hvad du laver.
Avatar billede DePlex Nybegynder
27. juni 2010 - 20:41 #21
Koden står i et af mine tidligere indlæg?
Avatar billede dkfire Nybegynder
27. juni 2010 - 20:48 #22
Da vel ikke den for den fejl. Den kode du har, vel jeg mene bør virke.
Avatar billede DePlex Nybegynder
27. juni 2010 - 20:59 #23
Jamen det gør den jo ikke? Den giver den der fejl?
Avatar billede dkfire Nybegynder
27. juni 2010 - 21:00 #24
Så er det fordi din $form ikke er et objekt af en klasse.
Avatar billede DePlex Nybegynder
27. juni 2010 - 21:13 #25
Hvad skal jeg så gøre. Kan du ikke kigge på det. Du har alle filerne her på siden.
Avatar billede DePlex Nybegynder
29. oktober 2010 - 17:43 #26
Har droppet log in systemet og har ikke rettet fejl :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester