PHP & mySQL: When exactly to use htmlentities?

Here’s the general rule of thumb. Escape variables at the last possible moment. You want your variables to be clean representations of the data. That is, if you are trying to store the last name of someone named “O’Brien”, then you definitely don’t want these: O'Brien O\’Brien .. because, well, that’s not his name: there’s … Read more

Proper session hijacking prevention in PHP

Your configuration is awesome. You definitely read up on how to lock down php sessions. However this line of code negates a lot of the protection provided by your php configuration: session_id(sha1(uniqid(microtime())); This is a particularly awful method of generating a session id. Based on your configurations you are generating the session id from /dev/urandom … Read more

How to do single sign-on with PHP? [closed]

Your question is too unspecific to give a precise answer. If you’re trying to let users log in to your website using Google accounts, it’s documented here. On the other hand, if you’re trying to let your users sign in to several websites you control with one account, here’s how you can do it: Make … Read more

PDO Exception Questions – How to Catch Them

You should look at the documentation. But If you dont find anything, you can add another catch : <?php try { $stmt = $db->prepare(“INSERT INTO tbl_user (id, name, password, question, answer) VALUES (NULL, :name, :password, :question, :answer)”); $stmt->bindValue(“:name”, $_POST[‘name’]); $stmt->bindValue(“:password”, $_POST[‘password’]); $stmt->bindValue(“:question”, $_POST[‘question’]); $stmt->bindValue(“:answer”, $_POST[‘answer’]); $stmt->execute(); echo “Successfully added the new user ” . $_POST[‘name’]; … Read more