Monday, January 13, 2014

Simple PHP PDO Class Implementation

Simple PHP PDO Class Implementation

$host = "127.0.0.1";
$db = "sample";
$username = "root";
$password = "";

$database = new PDO("mysql:host=" . $host . ";dbname=" . $db, $username, $password);

function find_user($username) {
 global $database;
 $p = $database->prepare("SELECT * FROM member WHERE username = ?");
 $p->execute(array($username));
 return $p->fetchObject();
}

$results = find_user("admin");
var_dump($results);

Out put of this function will be like bellow.
object(stdClass)[3]
  public 'id' => string '4' (length=1)
  public 'username' => string 'admin' (length=5)
  public 'password' => string '240824aa0487bca3bdd4deb847954b76' (length=32)
  public 'email' => string 'bthssssiban@gmail.com' (length=17)
  public 'postcode' => string 'Q2Z23S' (length=6)
  public 'status' => string 'Inactive' (length=8)
  public 'code' => string '4172f3101212a2009c74b547b6ddf935' (length=32)
  public '_date' => string '2011-02-17' (length=10)


echo $results->username; will prints the output of the username of value from the database.

Friday, January 10, 2014

Create htaccess folder password with htpasswd

Create htaccess folder password with htpasswd

Lets create the .htaccess file first

<IfModule mod_rewrite.c>
RewriteEngine off
</IfModule>
AuthName "Are You Real User"
AuthType Basic
AuthUserFile "/home/apweb/www/yourfolder/xo/.htpasswd"
require valid-user

Now we create the .htpasswd file, we have to generate the password so it will look like this

root:$apr1$2mMeQzaz$577FZ5p/E8EpdrsoVWFRg0

Please use the following URL to generate the username and the password



Finally copy and paste the generated code to your .htpasswd file and uplaod in to the server
Good Luck!