Jump to content

Andy-H

Members
  • Posts

    2,000
  • Joined

  • Last visited

  • Days Won

    1

Andy-H last won the day on January 3 2014

Andy-H had the most liked content!

About Andy-H

  • Birthday 04/02/1991

Contact Methods

  • MSN
    andy-holland@live.co.uk
  • Website URL
    http://cv.droppages.com/

Profile Information

  • Gender
    Male
  • Location
    Manchester - UK
  • Age
    22

Andy-H's Achievements

Advanced Member

Advanced Member (4/5)

8

Reputation

  1. Filtering user input requires different implementations depending on what you will be doing with the data, i.e. if you're writing data to a persistence layer, you should use methods appropriate to the persistence layer and abstraction layer that you're using, a few examples: PDO: // create database handle $stmt = $dbh->prepare('SELECT * FROM users WHERE username = ? LIMIT 1'); $stmt->execute(array($_POST['username'])); // we don't need to escape here as PDO prepared statements escape parameters for us mysql_* (which is deprecated, and will be moved into an extension, use PDO or MySQLi or something) // connect to database $result = mysql_query("SELECT * FROM users WHERE username = '". mysql_real_escape_string($_POST['username']) ."' LIMIT 1"); HTML <?= echo htmlspecialchars($_POST['username'], ENT_QUOTES, 'UTF-8'); ?> <?= echo htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8'); // replace with your character encoding ?> FYI: I would recomment htmlentities here as it translates all entities For a plain-text email, you won't need to escape your data, for a HTML email, you would escape it the same as you escape HTML output
  2. Ahh OK, which do you prefer out of interest? I'm currently using Laravel but I am not using eloquent, just using the QuesrBuilder as the base for a DAL.
  3. In that case just change company_id to company_name on the members table and change company_area_codes to member_area_codes and change company_id to member_id. (and forget about the companies table)
  4. Thought Proem was dead and you were using Laravel now?
  5. Hi Mark, I think you would be better splitting this into 4 tables, members, companies, area_codes and company_area_codes, see attachment. This way, companies can have multiple members, and their details do not need to be duplicated. They can also cover multiple area codes without duplication of the area code. Say you wanted to get all area codes that a company covers: SELECT ac.code FROM companies c INNER JOIN company_area_codes cac ON ( c.id = cac.company_id ) INNER JOIN area_codes ac ON ( ac.id = cac.area_code_id ) WHERE c.id = 1 You can also, of course, join the members table using company_id to get coverage for a member etc.
  6. You have created your $expectedKeys array incorrectly, you use: array($FName, $LName); // etc However, these variables are set to $_POST['fname'], $_POST['lname'] etc. This will result in an empty string, or the data posted, if the form has been submitted, so later in your script you are essentially calling: if ( !empty($_POST['']) ) or if ( !empty($_POST['some_random_name']) ) So you need to change your expected keys array to contain the relevant strings.
  7. Hi All, A friend of mine has asked me if I know of any PHP developers looking for work in the Manchester area, so I thought I'd post on here, in-case any of you guys were interested. The vacancy is at a commercial and leisure vehicle tracking company based in Stockport (SK1), they are currently expanding a small digital team due to growth. Ideal skills required are: OO PHP MySQL HTML CSS Javascript jQuery Google maps API V3 Experience with basic LAMP stack administration would also be advantageous. It's a relaxed work atmosphere and all the people that work there are really easy to get on with (I used to work there). They're offering a salary of between £22,000 and £27,000 depending on experience, and ideally want someone with 2+ years commercial experience or equivalent skill level. If you're interested the company is Phantom Ltd (http://phantom.uk.net) and you can apply via Monster (http://jobview.monster.co.uk/PHP-Web-Developer-Job-Stockport-North-West-UK-128645968.aspx) Regards, Andy
  8. Hi I am posting on behalf of a friend of mine who works for a leading digital agency in Manchester City Centre, they are currently recruiting for a PHP developer and an ASP.NET developer available for work in Manchester City Centre (http://www.reasondigital.com/contact-us/#contactusbottom). The role includes benefits such as: Great transport links (about 5 minutes from both Manchester Picadilly and Manchester Victoria train stations) Competitive salary (£26,000 - £32,000 DOE) Work with major clients such as BBC, Save the Children and Meningitis Trust A great company to work for with pleasant colleagues (I know two of their team personally) They're looking for someone with proficiency in (amongst other things): (OO) PHP MySQL Javascript / jQuery HTML/HTML 5 CSS For a full job description see: http://www.reasondigital.com/work-for-us/php-developer/ NO AGENCIES PLEASE!
  9. You can use PHP info: <?php php_info(); ?> Or run this in terminal: which php You should really just use Google to find this stuff...
  10. echo '<pre>'; foreach($result as $day => $store_data) { if ( !empty($store_data['open']) ) { echo "{$day}\t - {$store_data['open']} - {$store_data['close']}"; } else { echo "{$day}\t - Closed"; } }
  11. I'm not sure Google API has methods specifically for adding triangles, however, I'm sure if you looked into geo-fencing you could figure out how to draw a triangle.
  12. I would use the o.draw(img); example, simply because the interface doesn't limit you to only drawing one image to your 'tileSheet', i.e. you may in future need to draw 4 images. As for memory footprint, I would assume no to little difference as the same amount of objects are created in the same scope.
  13. Sorry, just tested those examples, fixed a mistake: <?phpabstract class FilterableProperties { protected $_data = array(); public function __set($key, $value) { if ( !in_array($key, array_keys($this->_data)) ) return null; $beforeFilter = "_before_set_{$key}"; if ( method_exists($this, $beforeFilter) ) { $this->_data[$key] = call_user_func(array($this, $beforeFilter), $value); } else { $this->_data[$key] = $value; } } public function __get($key) { return isset($this->_data[$key]) ? $this->_data[$key] : null; }}class Address extends FilterableProperties { protected $_data = array('property_name_or_number', 'street', 'town', 'city', 'county', 'postcode', 'country'); // now these properties can not be accessed and are actually protected protected $_country_code = null; protected $_country_codes = array( 'United Kingdom' => 'UK', 'United States' => 'USA', 'France' => 'FR', 'Germany' => 'GER' // ... ); protected function _before_set_postcode($newPostcode) { $newPostcode = strtoupper(preg_replace('/\s+/', '', $newPostcode)); if ( !preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/", $newPostcode) && !preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/", $newPostcode) ) throw new Exception('Invalid postcode'); return substr($newPostcode, 0, -3) .' '. substr($newPostcode, -3); } protected function _before_set_country($newCountry) { if ( !in_array($newCountry, array_keys($this->_country_codes)) ) throw new Exception('Invalid country'); $this->_country_code = $this->_country_codes[$newCountry]; return $newCountry; }} $Address = new Address();$Address->postcode = 'S K 1 51 T W';var_dump($Address->postcode); // SK15 1TW Still, I guess one mistake in untested code at 00:30 isn't too bad lol
  14. __get and __set are "magic" hook methods, they are called whenever a property is accessed on an instance of a class, and whenever a property is assigned a value on an instance of a class that implement them respectively. They can be used to control how a property is inserted into or retrieved from an object, I.e. they allow you to run post and/or pre-processing tasks to control the data that the object contains. Take the Address example: abstract class FilterableProperties { // this would be better as a trait public function __get($name) { $property = $this->_get_property($name); $beforeFilter = "_before_get_{$name}"; if ( method_exists($this, $beforeFilter) ) return call_user_func(array($this, $beforeFilter), $this->property); return $this->$property; } public function __set($name, $value) { $property = $this->_get_property($name); $beforeFilter = "_before_set_{$name}"; if ( method_exists($this, $beforeFilter) ) { $this->$property = call_user_func(array($this, $beforeFilter), $value); } else { $this->$property = $value; } } protected function _get_property($name) { $property = "_{$name}"; if ( !property_exists($this, $property) ) throw new Exception(sprintf('Property %s does not exist on %s', $name, get_class($this))); return $property; }}class Address extends FilterableProperties { protected $_property_name_or_number = null; protected $_street = null; protected $_town = null; protected $_city = null; protected $_county = null; protected $_postcode = null; protected $_country = null; protected $_country_code = null; protected function _before_set_postcode($newPostcode) { $newPostcode = strtoupper(preg_replace('/\s+/', '', $newPostcode)); if ( !preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/", $newPostcode) && !preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/", $newPostcode) ) { throw new Exception('Invalid postcode'); } else { return substr($newPostcode, 0, -3) .' '. substr($newPostcode, -3); } }} Now you are prevented from updating an instance to contain an incorrectly formatted postal code. You could also do things like set a country code from an associative array when a country gets set, or create a white-list of allowed values and throw an exception if the value is not contained. They are also used for creating storage objects, like so: class Storage { // this would be better as a trait again protected $_data = array(); public function __get($key) { if ( !isset($this->_data[$key]) ) return false; return $this->_data[$key]; } public function __set($key, $value) { $this->_data[$key] = $value; } } It is actually better to write the first example in a style similar to this, it gives us control over which properties can be accessed. abstract class FilterableProperties { // this would be better as a trait protected $_data = array(); public function __set($key, $value) { if ( !isset($this->_data[$key]) ) return null; $beforeFilter = "_before_set_{$key}"; if ( method_exists($this, $beforeFilter) ) { $this->_data[$key] = call_user_func(array($this, $beforeFilter), $value); } else { $this->_data[$key] = $value; } } public function __get($name) { return isset($this->_data[$key]) ? $this->_data[$key] : null; }}class Address extends FilterableProperties { protected $_data = array('property_name_or_number', 'street', 'town', 'city', 'county', 'postcode', 'country'); // now these properties can not be accessed and are actually protected protected $_country_code = null; protected $_country_codes = array( 'United Kingdom' => 'UK', 'United States' => 'USA', 'France' => 'FR', 'Germany' => 'GER' // ... ); protected function _before_set_postcode($newPostcode) { $newPostcode = strtoupper(preg_replace('/\s+/', '', $newPostcode)); if ( !preg_match("/^[A-Z]{1,2}[0-9]{2,3}[A-Z]{2}$/", $newPostcode) && !preg_match("/^[A-Z]{1,2}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{2}$/", $newPostcode) ) throw new Exception('Invalid postcode'); return substr($newPostcode, 0, -3) .' '. substr($newPostcode, -3); } protected function _before_set_country($newCountry) { if ( !in_array($newCountry, array_keys($this->_country_codes)) ) throw new Exception('Invalid country'); $this->_country_code = $this->_country_codes[$newCountry]; return $newCountry; }} Hope that helps.
  15. Ahh ok, try var_dump'ing that value that you're inserting until you get an integer (with the different casting techniques), then change all references to your $course->id variable to the working solution (the one that returns an integer).
×
×
  • 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.