Jump to content

carsonk

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

carsonk's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you. That was exactly what I was looking for.
  2. Hello, Is there a function to make a PHP file explicitly to be used as an include only? Or would it just be easier to set a variable in the parent page and test for it in the include page? I just wanted to make sure there wasn't a more efficient way than using the latter method. Thanks, Carson
  3. Hi, I'm wondering what would be the most efficient way to go through, loop through the first three rows of a MySQL Table, then do something different on the fourth, fifth, sixth, and change back again on the seventh. I would like this pattern to continue until all the tables are used up. I would also like to make sure it can not only end on a number that is divisible by three, like fourteen. Thanks!
  4. Would it be a game where you click a link and your points go up, and just have it with text? Or are you actually going to make something like a Flash game with animation, graphics, etc.?
  5. Just thought I'd come in and introduce myself! I'm Carson, and for my knowledge of PHP, I understand the fundamentals, but I'm interested in learning a bit more. Thanks!
  6. I apologize if this topic is in the wrong forum. I created a login class, but I don't believe it is as efficient as it could be. So, if a couple people could tell me if what I did was best or if there is a more efficient way to do it. I'm just including the login class, but if you need any more info, just ask and I'll see if I can get it for you. class login { var $db; var $username; var $u_id; var $input_password; var $md5_password; var $remember = FALSE; var $rem_days = 0; var $banned = FALSE; var $ban_time = 0; var $ban_reason; public function __construct($db, $username, $password, $remember, $rem_days) { $this->db = $db; $this->username = $username; $this->password = $password; $this->remember = $remember; $this->rem_days = $rem_days; } //.................. //PRIVATE FUNCTIONS //.................. private function get_uid() { $query = "SELECT * FROM users WHERE username = '".$this->username."'"; $result = $this->db->query($query); $row = $result->fetch_array(MYSQLI_ASSOC); $id = $row["id"]; $this->u_id = $id; return $id; } private function convert_pass() { $this->md5_password = md5($this->input_password); return $this->md5_passport; } //if the function returns 1, user is banned private function check_ban() { $query = "SELECT * from bans WHERE user_id = ".$this->convert_pass()." AND end_time < ".time()." ORDER BY 'end_time' DESC"; $result = $this->$db->query($query); if ($result->num_rows >= 1) { $this->banned = TRUE; $row = $result->fetch_array(MYSQLI_ASSOC); $this->banned = TRUE; $this->ban_time = $row["end_time"]; $this->ban_reason = $row["reason"]; return TRUE; } else { return FALSE; } } //.................. //PUBLIC FUNCTIONS //.................. public function check_login() { $this->convert_pass(); $this->get_uid(); $query = "SELECT * FROM users WHERE id = '".$this->u_id."' AND password = '".$this->md5_password."'"; $result = $this->db->query($u_query); if ($result->num_rows == "1") { if (!$this->check_ban()) { return TRUE; } else { echo "BANNED!"; return FALSE; } } else if($result->num_rows > 1) { echo "Uh-oh! It looks like there are two accounts with the same username! Please send an email to an admin immediately to correct this problem."; return FALSE; } else { return FALSE; } } public function set_session() { session_start(); $_SESSION["username"] = $this->username; $_SESSION["u_id"] = $this->u_id; $_SESSION["unique"] = md5($this->md5_password); if($remember) { setcookie("remember", "", time()+(3600*24)*($this->rem_days)); } } public function fail_reason() { } //NOTE: WHEN LOGGING OUT, COOKIES MUST BE DELETED BEFORE ANY OUTPUT IS MADE (so, place before header.php or anything with an echo function) public function logout() { session_destroy; if($_COOKIE["rem"]) { setcookie("remember", "", time()-3600); } } }
×
×
  • 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.