Jump to content

Far Cry

Members
  • Posts

    89
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Far Cry's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. <?php class Session { public $loggedin; public function CheckLogin($userid,$username) { if(isset($userid) && isset($username)){ $this->loggedin = true; } else { $this->loggedin = false; } return $this->loggedin; } public function Login(){ if($this->CheckLogin(....?)){ } } } ?> Would I need to pass the variables to the CheckLogin function in the if statement to get the true/false value? If so, how?
  2. What are some ideas for a text based mmo?
  3. So I have a validation class, and it puts all errors that occur within an array. However when I try and use foreach to get these values, only one gets returned. Even if there are multiple errors. validation.php: <?php class RegisterValidation { public $error = array(); public $valid; public function ValidateUsername($username) { /* X First sanatize username. X Then check length. Then chick if username exists in DB or not. */ trim($username); strip_tags($username); mysql_real_escape_string($username); $len = strlen($username); if ($len < 3 || $len > 20){ $this->valid = false; $this->error[] = "Your username must be 3 to 20 characters in length."; } else { $this->valid = true; } if(!$len < 3 || !$len > 20){ $checkusername = mysql_query("SELECT username FROM users WHERE username = '$username'"); if(mysql_mum_rows($checkusername) == 1){ // usename is found, throw out error $this->valid = false; $this->error[] = "That username is already in use."; } else { $this->valid = true; } } return $this->valid; } public function ValidatePassword($password,$repassword) { /* First sanatize. Then check if pass has at least one upper, lower, and one number. */ trim($password); strip_tags($password); mysql_real_escape_string($password); trim($repassword); strip_tags($repassword); mysql_real_escape_string($repassword); if(!preg_match('/[A-Z]/', $password)) { $this->valid = false; $this->error[] = "Your password must contain at least one upper-case letter."; } else { $this->valid = true; } if(!preg_match('/[a-z]/',$password)) { $this->valid = false; $this->error[] = "Your password must contain at least one lower-case letter."; } else { $this->valid = true; } if(!preg_match('/[0-9]/',$password)) { $this->valid = false; $this->error[] = "Your password must contain at least one number."; } else { $this->valid = true; } if($password !== $repassword){ $this->valid = false; $this->error[] = "Your passwords do not match."; } else { $this->valid = true; } return $this->valid; } public function ValidateEmail($email, $reemail){ /* Sanatize. User filter_var to validate. Make sure both emails match. Check if email already exists or not. */ trim($email); strip_tags($email); mysql_real_escape_string($email); trim($reemail); strip_tags($reemail); mysql_real_escape_string($reemail); if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $this->valid = false; $this->error[] = "The E-Mail that you provided is not valid."; } else { $this->valid = true; } if($email !== $reemail){ $this->valid = false; $this->error[] = "The E-Mail's that you provided do not match."; } else { $this->valid = true; } if(filter_var($email, FILTER_VALIDATE_EMAIL) && $email == $reemail){ $checkmail = mysql_query("SELECT users.email, temp_users.email FROM users, temp_users WHERE email = '$email'"); if(mysql_mum_rows($checkmail) == 1){ // email is found, throw out error $this->valid = false; $this->error[] = "That E-Mail is already in use."; } else { $this->valid = true; } } return $this->valid; } ?> register.php (snippet): if($register->ValidateUsername($username) && $register->ValidatePassword($password, $repassword) && $register->ValidateEmail($email, $reemail)) { //Add user } else { foreach($register->error as $error){ echo "<span class=\"error\">".$error."</span>"; } } Thanks!
  4. Hmm :/
  5. The following script just validates some form inputs, and then puts any errors inside an array. I get this error: Fatal error: Cannot use [] for reading in C:\xampp\htdocs\Game\includes\validation.php on line 104 I've looked around, and this still does not make any sense to me. public function ValidateEmail($email, $reemail){ /* Sanatize. User filter_var to validate. Make sure both emails match. Check if email already exists or not. */ trim($email); strip_tags($email); mysql_real_escape_string($email); trim($reemail); strip_tags($reemail); mysql_real_escape_string($reemail); if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $this->valid = false; //Line 104 $this->error[] - "The E-Mail that you provided is not valid."; } else { $this->valid = true; } if($email !== $reemail){ $this->valid = false; $this->error[] = "The E-Mail's that you provided do not match."; } else { $this->valid = true; } if(filter_var($email, FILTER_VALIDATE_EMAIL) && $email == $reemail){ $checkmail = mysql_query("SELECT users.email, temp_users.email FROM users, temp_users WHERE email = '$email'"); if(mysql_mum_rows($checkmail) == 1){ // email is found, throw out error $this->valid = false; $this->error[] = "That E-Mail is already in use."; } else { $this->valid = true; } } return $this->error; } Line 104 is commented out. Thanks!
  6. Thank you so much, guys. It really is the little things that matter.
  7. I am writing a validation script that validates the inputted username and password, although not totally finished. I just decided to test it and see if it was working as it should. I get these errors when running this file: Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 5 in C:\*****\*********\********\includes\validation.php on line 21 Warning: Invalid argument supplied for foreach() in C:\****\******\******\includes\validation.php on line 75 What this is supposed to do hold all errors in an array, and then echo them out to the user. And the valid property is self-explanatory. <?php class RegisterValidation { public $error = array(); public $valid; public function ValidateUsername($username) { /* X First sanatize username. X Then check length. Then chick if username exists in DB or not. */ trim($username); strip_tags($username); mysql_real_escape_string($username); if(!preg_match('/{3,20}/', $username)){ $this->valid = false; $this->error = "Your username must be 3 to 20 characters in length."; } else { $this->valid = true; } return $this->valid; } public function ValidatePassword($password,$repassword) { /* First sanatize. Then check if pass has at least one upper, lower, and one number. */ trim($username); strip_tags($username); mysql_real_escape_string($username); if(!preg_match('/[A-Z]/', $password)) { $this->valid = false; $this->error = "Your password must contain at least one upper-case letter."; } else { $this->valid = true; } if(!preg_match('/[a-z]/',$password)) { $this->valid = false; $this->error = "Your password must contain at least one lower-case letter."; } else { $this->valid = true; } if(!preg_match('/[0-9]/')) { $this->valid = false; $this->error = "Your password must contain at least one number."; } else { $this->valid = true; return $this->valid; } } } $register = new RegisterValidation; $usertest = "uyrewuiy"; $register->ValidateUsername($usertest); foreach ($register->error as $error){ echo $error; } ?> Thanks in advance.
  8. I have an items table that holds basic info such as id, name, damage etc. values of that item My question is: If I wanted to add a shop where users could buy items, would it be a good idea to make a new database table that holds just one column per item that would be sold at that shop and have it contain the same values as the items table. Then once that item is purchased, have those values copied to the items table? May sound confusing. Just don't know if this idea is at all efficient.
  9. Far Cry

    Div problems

    For some reason, it seems the attack-items div is going outside the content div, (hence the border). I'm trying to make it so the attack-items and attack-items-header divs lay on top of each other, I'm out of ideas here. HTML <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Crime Town</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="js/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js"></script> </head> <body> <div id="container"> <div id="header"> <img src="images/originallogo.png"> </div> <div id="navbar"> <ul> <li><a href="index.php">Home</a></li> <li><a href="admin.php?page=home">Admin Panel</li> <li><a href="items.php">Items</a></li> <li><a href="shops.php">Shops</a></li> <li><a href="logout.php">Logout</a></li> </ul> </div> <br /> <div id="user-info-header"><span id="span-user-info-header">User Info</span></div> <div id="user-info"> <ul> <li>Name: Administrator</li> <li>Level: 1</li> <li>Cash: $10,000,003,939</li> <li>Health: 5,000/5,000</li> <li>Energy: 100/100</li> <li>Nerve: 10/10</li> </ul> </div> <div id="content" align="center" style="border: 5px solid red;"> <div id="attack-items-header">Your Items</div> <div id="attack-items"> <table cellspacing="10"> <tr> <td>Primary</td> <td>Secondary</td> <td>Melee</td> </tr> <td><a href="attack.php?action=use&it_id=18">Shotgun</a></td><td>None</td><td>None</td></table> </div> </div><!--Content--> </div><!--Container--> </body> </html> CSS #attack-items { font-weight:bold; width:250px; border:2px solid #000; margin-left:5px; margin-top:300px; margin-bottom:-300px; } #attack-items-header { width:250px; background-color:#000; margin-top:300px; } #container { height:100%; } #content { margin-top:-143px; margin-bottom:143px; } Thanks!
  10. Try to add this to the top of your script after session_startof course... error_reporting(E_ALL); This will display all errors on the page. Maybe that will help.
  11. "$" is not a valid variable.
  12. I'm a Sophomore in high school taking a web design class just for an easy A. I have been doing HTML and CSS for about 2 years (since I was 14), then started doing PHP and MySQL for about a year, I am somewhat proficient with that. The class started out okay, but the past few weeks have been HELL. The teacher is learning CSS basically along with the rest of the class, and has no idea what she's doing. How do I deal with these noobs?! :'( I can't handle this!
  13. 1). Magic qoutes was used to escape strings to prevent MySQL injection, just use mysql_real_escape_string();. 2). <? session_start(); if(!session_is_registered(fusername)){ header("location:sfjogin.php"); } ?> Should be... <?php session_start(); if(!$_SESSION['fusername']){ header("Location:sfjogin.php"); die(); } ?> 3). Never use shorthand (<? ?>) PHP. Bad practice.
  14. Thanks for the info.
  15. can you give me a sample code for this case ? <?php //Start output buffer so we can use header(); to redirect. Not needed if you are not using sessions. ob_start(); $current_ip = $_SERVER['REMOTE_ADDR']; $query = mysql_query("SELECT blocked_ip FROM tbl_name_here WHERE blocked_ip=$current_ip"); //If IP matches DB's IP, redirect. if(mysql_num_rows($query) == 1){ header("Location:someplace.php"); } else { //IP is not blocked, continue. } //End output buffer ob_end_flush(); ?> Code is untested, should work.
×
×
  • 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.