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!

Thursday, November 21, 2013

Disable directory browsing in CentOs 6.4 apache/httpd

How to Disable directory browsing in apache httpd.conf ?


Answer: Actually you are totally right that you wish to disable this feature. One of the “must do’s” on setting a secure apache web server is to disable directory browsing. Usually apache comes with this feature enabled but its always a good idea to get it disabled unless you really need it.

First of all find where is the main apache’s config file httpd.conf is located. If you use Debian, it should be here: /etc/apache/httpd.conf. Using some file editor like Vim or Nano open this file and find the line that looks as follows:

Options Includes Indexes FollowSymLinks MultiViews

then remove word Indexes and save the file. The line should look like this one:

Options Includes FollowSymLinks MultiViews

for the subdomains:

To allow directory browsing for sub-domains and blocked in the main domain as become as follow.
Options Includes FollowSymLinks MultiViews
<VirtualHost *:80>
DocumentRoot "/var/www/downloads"
ServerName downloads.facebook.com
ErrorLog "logs/facebook"
CustomLog "logs/facebook_custom" common
<Directory "/var/www/downloads">
allow from all
Options +Indexes
</Directory>
</VirtualHost>

If no file from the DirectoryIndex directive can be located in the directory, then mod_autoindex can generate a listing of the directory contents. This is turned on and off using the Options directive. For example, to turn on directory listings for a particular directory, you can use:

<Directory /usr/local/apache2/htdocs/listme>
  Options +Indexes
</Directory>

To prevent directory listings (for security purposes, for example), you should remove the Indexes keyword from every Options directive in your configuration file. Or to prevent them only for a single directory, you can use:
<Directory /usr/local/apache2/htdocs/dontlistme>
  Options -Indexes
</Directory>

CentOS 6.4 Create FTP Users

How to Create FTP Users in CentOs 6.4?

- Add a user called "bira"
# useradd bira

Add a password for the user "bira"
# passwd bira (Enter)

New password: (enter your password)

Retype new password: (enter the same password again)
passwd: all authentication tokens updated successfully.

Now give the directory access for the user.
Change the ownership for the "html" directory 
# chown bira /var/www/html

Change the group for this "html" directory .
#chgrp bira /var/www/html

list the directories and check
# ls -l
drwxr-xr-x. 3 bira bira 4096 Nov 21 13:23 html

Finally re-start the vsfptd server.
# service vsftpd restart

All done! just trying to connect with your FileZilla ftp client.

if not:

Do you have SELinux enabled?

To check: # sestatus

If SELinuxstatus = on & Current mode = enforcing, it's all enabled... 
so lets turn it to permissive mode.

Permissive mode: # setenforce 0

Check sestatus again, and it should be Current mode = permissive. This basically leaves SELinux on, but in a log only manner.

All done! just trying to connect with your FileZilla ftp client.

If you still having issues please let me know my self.

Monday, November 18, 2013

“Denied access” problem when using Wamp server 2 on Windows 8



“Denied access” problem when  using Wamp server 2 on Windows 8



First, open the httpd.conf file of your apache version by a text editor such as Notepad or Notepad++. It’s usually located at \wamp\bin\apache\<your apache version>\conf\httpd.conf or you can use the quick menu of Wamp manager to open it. Find these snippet before modify it:

# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

Replace the Deny from all with Allow from all and save the file.We have not finished yet. Find another snippet:

#   onlineoffline tag - don't remove
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1

Replace Deny from all with Allow from all again. The localhost runs correctly now.After do all above thing, I believe that you can locate to localhost and your local web project with your browser. However, if you navigate to http://localhost/phpmyadmin, you will continue getting the Forbidden error. The reason is you did not modify the alias configuration file to allow access from your localhost. Let open this file by using Wamp manager or finding it in \wamp\alias\phpmyadmin.conf, find this snippet

<Directory "c:/wamp/apps/phpmyadmin3.4.10.1/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>


Change Allow from 127.0.0.1 to Allow from ::1 or you can do as above, change Deny from all into Allow from all. Now, that’s all.

Tuesday, November 12, 2013

FileZilla - Disable the password autosave feature

To disable this feature under FileZilla: 




  1. Click on the "Edit" menu > Settings > Interface
  2. In the "Behaviour" section, check "Do not save passwords".
  3. Click on OK to validate.



Monday, November 11, 2013

CentOS 6.x make visible .htaccess file on ftp / vsftpd

Server OS: Centos 5.x / VSFTPD

Client: Windows 7 /Filezilla

You have uploaded an .htaccess file to your FTP space. You click refresh and the file disappears. Do not worry. The file is there – it is simply not displaying as it is classed as a hidden file. If you have shell access then SSH to your server and run:

 ls -a

You should see the file listed.
In this scenario, to see the hidden files via your FTP client edit the vsftpd.conf file:

 vi /etc/vsftpd/vsftpd.conf

And add the following line force_dot_files=YES
Dont forget to restart the FTP service! /sbin/service vsftpd restart