Reputation Activity
-
Jock got a reaction from BrowserBugs in Inspecting ImagesYour $fileLocation variable is probably not a correct file path, it also doesn't need to be in quotes. If file_get_contents cannot find the file in that path it will return false, so your code is passing the boolean false into imagecreatefromstring, and will probably thrown that data is not in a recognized format warning. Echo the $fileLocation variable first to verify it exists, you can also wrap the file_get_contents line in an if statement to prevent the code from being executed if the file cant be found.
-
Jock got a reaction from Keo in Hungarian guy looking for your job applying experiences...It all boils down to how good you are and how much commercial experience you have.
In my experience its much quicker in the UK. I think the throughput of developers is very high, usually developers working for digital agencies will jump ship every 18 months: they get bored, overworked, under-challenged, underpaid etc. So they look for something new... recruiting is quite painless as it happens so often.
Applying for a job usually involves sending a CV and covering letter. Then if they like the look of you you'll get an interview. They might ask you to complete a quiz or some test to check your abilities. After that they'll usually hire you or they wont, a second interview is not very common here. If there are 2 then the first will probably be with HR and the second will be with the lead developer.
As I said above it really depends on how good you are & how much commercial experience you've got it also helps if you can start immediately because its not uncommon to be offered the job in the very first interview. 2 of the 3 jobs I've had I was offered them in the interview, even before they had seen other candidates. Nowadays companies have started coming to me to asking if I want a job. That sounds very arrogant but it happens, if you tick all the boxes then they'll want to get you on board as quick as possible.
Take code printouts with you to the interview. Something that’s relevant to their business, like a paypal API for an ecommerce company. And put some easter eggs in your code to see if their senior developer can spot them
PS please don’t be spam because this took ages to type...
-
Jock reacted to andy9l in How do you include php in your meta tags?This is not the way to approach what you're trying to do. Research into object oriented programming, specifically PHP, and then try to get an understanding of something called Model-View-Controller (MVC). At the very minimum - mysql is discouraged, you should use PHPs PDO or a mysqli database class.
Also, it looks like you're trying to print meta tags in a loop - so you'll end up with several descriptions, etc.. This does not make sense.
Edit: As a starting point, try running this. I've just written it out so might not work perfectly for you. Again, it would be better to use PDO, but this is somewhat simpler and closer to your original.
<? define('DB_HOST', 'localhost'); define('DB_USER', 'root'); define('DB_PASS', ''); define('DB_NAME', 'movie_database'); class Database{ private $con, $result; public function __construct($host, $user, $pass, $db){ $this->con = @new mysqli($host, $user, $pass, $db); if ($this->con->connect_error){ die ("Database connection error: " . $this->con->connect_error); } } public function query($sql){ $this->result = @$this->con->query($sql); if ($this->result === FALSE){ die ("Database query error: " . $this->con->error); } } public function get_result(){ return $this->result; } public function close(){ $this->con->close(); } } $database = new Database(DB_HOST, DB_USER, DB_PASS, DB_NAME); $database->query("SELECT * FROM movies"); if ($database->get_result() !== FALSE){ while ($movie = mysqli_fetch_array($database->get_result())){ //You should have a Movie class rather than relying on an array echo "Title: {$movie['title']}<br />\nKeyword: {$movie['keywords']}<br /><br />"; } } $database->close();
-
Jock got a reaction from Revs in Data lost in MySQL tableALTER TABLE `xxxxxxxx` AUTO_INCREMENT = 1;
-
Jock got a reaction from snick in Correct PHP FormattingYeah, I agree with rallport, you should use MVC to separate the business logic from the display, it makes it a lot easier to read.
EDIT: Just realised this ****ty editor doesn't work so ignore what i said about using PEAR style
-
Jock reacted to Skateside in Mastering JavascriptDownvote! Dislike!
... we need a button for that ...
Pure Javascript is far more versatile than jQuery, jQuery is pretty limited to the browser whereas Javascript is appearing in browsers, serves, TVs, mobile phones, Windows 8 ... there's no reason to limit yourself to a browser-based library like that.
Back to the question at hand, there are a few good books I can recommend (all with handy links to Amazon). Each of them generally keep away from code examples using libraries and their advice can be used on any platform.
Javascript: The Good Parts by Douglas Crockford - this is a must read generally. Crockford defines a sub-set of Javascript that stays away from the language's more esoteric or confusing elements. Having read this book (and cyber-stalked Doug through YUI theatre), I found my code less confusing to other people (including myself) and better laid out. I can read old code much better now than I could in years gone by.
Pro Javascript Design Patterns by Ross Harmes and Dustin Diaz - this was the book that got me thinking along object oriented lines and finally understanding that programming concept. The book goes through classic programing patterns and just knowing about those helped me code in a more logical way, opening up inheritance to me for the first time.
Maintainable Javascript by Nicholas C Zakas - I'm only part way through this book and already it's helped me make my code more maintainable. This has the advantage of making more sense in the future as well as maintaining large applications. This book also has some great advice about coding Javascript in a team.
I hope that helps
-
Jock got a reaction from zed in PHP create PDFLiveDocx web service is exactly what you need. You make a Microsoft word template and push that to the livedocx web service along with your data and it will populate it.
http://www.livedocx.com/
-
Jock got a reaction from ELITE in Help With OOPI have attached some form validation classes for you to look at. Its something I wrote a few years ago and never got round to finishing!
<html> <head> <title>Form demo</title> <style> .error { border: 1px solid red; } dt { float: left; } dt.required { background: transparent url("images/asterisk.png") no-repeat top right; padding-right:10px; } dd { margin: 0em 0em 1em 11em;} </style> </head> <body> <?php error_reporting(-1); ini_set('display_errors', 'on'); ini_set('display_startup_errors', 'on'); function autoLoader($className){ $path = str_replace('_', '/', $className); include_once '../library/'.$path.'.php'; } spl_autoload_register('autoLoader'); $form = new Fluid_Form(); $form->addProcessor(new Fluid_Form_Processor_Email()); $name = new Fluid_Form_Element_Input_Text('name'); $name->setLabel('Your name') ->addFilter(new Fluid_Filter_Alnum()) ->setRequired(true, true) ->addValidator(new Fluid_Validate_String(array('maxLength'=>32, 'minLength'=>3))); $password = new Fluid_Form_Element_Input_Password('password'); $password->setLabel('Password') ->setRequired(true, true) ->addValidator(new Fluid_Validate_String(array('maxLength'=>32, 'minLength'=>3))); $email = new Fluid_Form_Element_Input_Text('email'); $email->setLabel('Email Address') ->setRequired(true) ->addValidator(new Fluid_Validate_String(array('maxLength'=>128, 'minLength'=>)) ->addValidator(new Fluid_Validate_Email); $select = new Fluid_Form_Element_Select('team'); $select->setLabel('Favourite Team') ->setMultiOptions(array('rangers', 'celtic', 'hibs', 'hearts', 'motherwell', 'aberdeen')); $submit = new Fluid_Form_Element_Input_Submit('btnSubmit', array('label'=>'Send Enquiry')); $form->addElements(array($name, $password, $email, $select, $submit)); if($_SERVER['REQUEST_METHOD'] === 'POST') { if($form->isValid($_POST)) { echo "Form is valid."; $form->process(); } else { echo $form; } } else { echo $form; } ?> </body> </html>
Would render something like...
Obviously you wouldn't have it in an HTML file, you would make your own form My_Form extend Form but its just an example. Let me know if you need any more info.
Fluid.zip
-
Jock got a reaction from sash_oo7 in My website got hacked 5th time in a span of few monthsEverything posted above is sound advice.
I looked at the source code of your site, I saw 'timthumb' script being used. I'm very way of scripts like this, its dumb fatal to do any kind of image manipulation on the front side that is saved onto a server. I googled it and yeah there are some TimThumb vulnerability articles.
-
Jock got a reaction from Bravo81 in Little help on While Loops with an Array.You cant use mysql library functions on PDOStatement objects. Its like trying to play a SNES game in an PS3.
You need to use PDO to fetch the result
while($i1 = $sth->fetch(PDO::FETCH_OBJ)) { echo 'Subject: $i1->ticket_subject - $i1->ticket_date - Status: $i1->ticket_responded - View Ticket.<br>'; }
-
Jock got a reaction from Renaissance-Design in CMS + Page Builder Projectmysql_fetch_array accepts a mysql resource as a parameter, not an sql query.
So you want to first get a mysql resource before you can fetch your results.
$query = mysql_query("SELECT * FROM article WHERE id='1'"); $content = mysql_fetch_array($query);
Now this will probably cause uproar on this forum, but... mysql_ functions are ancient, think of them as the IE6 of database extraction methods. Sure they still work but seeing as you're learning you might as well use a modern approach.
PDO is a much nicer solution http://www.php.net/manual/en/class.pdo.php
// database parameters $dsn = 'mysql:dbname=testdb;host=127.0.0.1'; $user = 'dbuser'; $password = 'dbpass'; // try to create a new PDO object try { $database = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } // prepare a query $query = $database->prepare('SELECT * FROM article WHERE id=?'); // execute your query (passing an array of parameters) $query->execute(array(1)); // fetch all the data associated with the query $article = $query->fetchAll(); // now do something with that data print_r($article);
-
Jock got a reaction from Malyo in What is average Front-End Dev salary in England?http://www.itjobswatch.co.uk/jobs/uk/front-end%20developer.do -
Jock got a reaction from Twan in Fun with checkboxesYou need to give your checkbox a value attribute.
<input name="chktest" type="checkbox" value="on" />
-
Jock got a reaction from MikeChipshop in Local serverinb4 xamp
Zend Server CE is the best in my opinion
http://www.zend.com/en/products/server-ce/
-
Jock got a reaction from Renaissance-Design in Local serverinb4 xamp
Zend Server CE is the best in my opinion
http://www.zend.com/en/products/server-ce/
-
Jock got a reaction from Renaissance-Design in Variables in a class - where and when to declare/set, and using in a function?A 'variable' inside a class (called a class member variable) should have $'s otherwise PHP will probably assume they're constants. Next, the 'var' keyword is from PHP4 - get rid of it and start using public, private or protected to define the variable scope. Public can be accessed from anywhere, protected can only be accessed by a child or parent class, private can only be accessed from the class itself..
class FacebookProfile { private $password = '$3cr3tPassw0rD'; protected $birthday = '31/01/1990'; public $name = 'Jock'; }
The PHP docs on class member visibility explain this pretty well - http://www.php.net/manual/en/language.oop5.visibility.php
Anyway onto your question: There is no standard way of defining variable values. Personally if I have default values, I will hard code them into the variable definition at the top of the class, rather than setting them within the constructor. When you need to access or edit a member variable, it's much better practice to use an Accessor/Mutator method, read more on this on wikipedia - http://en.wikipedia.org/wiki/Mutator_method
It might look like hard work but an IDE like netbeans will automatically write getters/setters for you automatically.
-
Jock got a reaction from Anonimista in PHP 'private' classI typically for this you'd use an abstract factory http://sourcemaking.com/design_patterns/abstract_factory
But it doesn't really solve your 'security' problem. I guess you need to make your class aware of its constructor, so something like...
class Wheel { public function __construct($car) { if($car instanceof Car) { // do stuff } else { throw new InvalidArgumentException('Must be constructed by a car'); } } } //inside car $wheel = new Wheel($this);
-
Jock got a reaction from Anonimista in PHP class modifiersI've been coding PHP for years and never used a final method in an abstract class. I guess you might want to use it to stop overloading methods from the abstract parent. e.g if you had a strict constructor that the some code later relied on the class being instantiated in a certain way. (which probably constitutes bad application design)
This is a design trait of PHP, because a constant cannot be redefined there would be no reason to restrict via a protected or private identifier. In PHP access identifiers are there to restrict changing values, not accessing. Accessing members without a getter is dirty.
Yes, if it was a protected or private static member you would access it using self::myVar or parent::myVar
To stop overwriting. Again, I can count the number of times I've used a final class on my hand, and most of them have been for crude debugging. Typically you would use it on utility classes which are fundamental in your application. e.g
final class Integer { public function get() { $random = rand(); return (integer) $random; } } // would stop something like this happening class TrollInteger extends Integer { public function get() { $random = rand(); return (string) $random; } }
I don't know what you're trying to achieve with that object you posted. If you want to try all that stuff I would split it up into practical examples. Do you need any more help? I can post some examples if you need anything.
-
Jock got a reaction from Anonimista in PHPUnit and methods that manipulate objectsLooks fine to me.
Most PHP frameworks come with test cases, so maybe you can browse some of their tests if its example code you're looking for.
http://framework.zend.com/svn/framework/standard/trunk/tests/Zend/
-
Jock got a reaction from tonychang in Dual external monitors with a laptopSome docking stations have VGA and DVI ports so you can run dual monitors. Or grab a USB graphics adapter?
-
Jock got a reaction from Lev in What is "Reputation" in profiles.I gave you +1 so now you're on -4
I think it might be something to do with the date you joined and posts per day or something?
-
Jock reacted to henbast in Encryption algorithmsBcrypt. You can use the unfortunately named phpass to handle it. Everything else is pretty much a waste of time. -
Jock got a reaction from DigitalSquid in OOP it is not being printed outIf your object is a polymorphic string then you should use the __toString method so PHP can treat it like a string. Also don't allow object methods print/echo/output anything, they should only return a value and the calling script should decide what to do with that returned value.
class TextBoxSimple { private $body_text = "my_test"; private function display() { return sprintf('<table border="1"><tr><td>%s</td></tr></table>', $this->body_text); } public function __toString() { return $this->display(); } } $textBoxSimple = new TextBoxSimple; echo $textBoxSimple;
What book is this from?
-
Jock got a reaction from Jack Ellis in User Class - Which Design Pattern?Because I wanted to store the user objects within the registry in an array fashion, I made the Users registry object extend the SPL ArrayAccess object, which will make the object 'act' like an array.
So offsetSet($key, $value) is similar to procedurally $array[$key] = $value, and offsetGet($key) is like $array[$key]. Essentially they're just setting and getting an array value. Ultimately this will make our Users object look and act like an array, where the key is the user id and the value is the user object.
The point of all that is that you now have a robust method of storing users and can interface with the class using all sorts of useful ways like you can with an array.
//get the instance of Users $users = Users::getInstance(); //access a indice as like an object echo $users[2]->myMethod(); //count it echo count($users); //traverse it foreach ($users as $user) { echo $user->helloWorld(); }
-
Jock got a reaction from Jack Ellis in User Class - Which Design Pattern?I'd use the registry pattern to hold user object instances.
<?php // example users class class User { private $id; public function __construct($id) { $this->id = $id; } } class Users extends ArrayObject { protected $container = array(); private static $instance; /** * @return Users */ public static function getInstance() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c; } return self::$instance; } public static function getUser($name) { $instance = self::getInstance(); if ($instance->offsetExists($name)) { return $instance->offsetGet($name); } else { $user = new User($name); $instance->offsetSet($name, $user); return $user; } } } Users::getUser(1); Users::getUser(2); Users::getUser(3); Users::getUser(1); Users::getUser(1); Users::getUser(1); Users::getUser(1); $users = Users::getInstance(); echo count($users);