Friday, April 24, 2015

Prevent accessing XAMPP, Wamp , any server localhost from another local PC by IP



use the commands given in image

1.   insert : $ su
2.   insert password: *******
3.                # cd/etc/apache2/
4.   now there is a file for edit in apache editing
5.   comment the "require all granted "
6    Add "Require ip 127.0.0.1"
7    restart apache 
8                              # sudo service apache2 restart



Happy coding :)

nobody can check your directory by your IP
Read more....

Thursday, April 23, 2015

Robomongo (v 0.8.4) connection to use localhost (127.0.0.1)

I set the Robomongo (v 0.8.4) connection to use localhost (127.0.0.1) and port 3001. Everything else is empty/default. I am using Ubuntu 14.4 LTS . 

My Robomongo settings:

Connection tab Authentication tab Advanced tab SSL tab SSH tab
Read more....

Thursday, April 16, 2015

Ubuntu Linux: Install or Add PHP-GD To Apache Web Server

The GD Graphics Library for dynamically manipulating images. You will need to compile PHP with the GD library of image functions for this to work. However. Ubuntu (and Debian) Linux comes with the package called php5-gd.
 Just type the following command to install this module:

 
# apt-get install php5-gd
 

OR


 
$ sudo apt-get install php5-gd
 


Finally, restart the Apache 2 web server, enter:


 
# /etc/init.d/apache2 restart
 




Now, you can test your php application.


How do I verify that php5-gd support loaded or not?

Type the following command at a shell prompt:


 
$ php5 -m | grep -i gd
 



Sample outputs:

 
   gd
 



OR


 
$ php5 -i | grep -i --color gd
 



OR


 
$ php -i | grep -i --color gd
 


Read more....

Wednesday, April 8, 2015

PHP Question Set 01

1. Who is the father of PHP ?
Rasmus Lerdorf is known as the father of PHP.


2. What is the difference between $name and $$name?
$name is variable where as $$name is reference variable like $name=sonia and $$name=singh so $sonia value is singh.


3. What are the method available in form submitting?
GET and POST

4.How can we get the browser properties using PHP?
<?php
echo $_SERVER[‘HTTP_USER_AGENT’].”\n\n”;
$browser=get_browser(null,true);
print_r($browser);
?>


5. What Is a Session?
A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests. Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

6. How can we register the variables into a session?
<?php
session_register($ur_session_var);
?>


7. How many ways we can pass the variable through the navigation between the pages?
Register the variable into the session
Pass the variable as a cookie
Pass the variable as part of the URL


8. How can we know the total number of elements of Array?
sizeof($array_var)
count($array_var)


9. How can we create a database using php?
mysql_create_db();

10. What is the functionality of the function strstr and stristr?
strstr() returns part of a given string from the first occurrence of a given substring to the end of the string.
For example:strstr("user@example.com","@") will return "@example.com".
stristr() is idential to strstr() except that it is case insensitive.


11. What are encryption functions in PHP?
CRYPT(), MD5()

12. How to store the uploaded file to the final location?
move_uploaded_file( string filename, string destination)

13. Explain mysql_error().
The mysql_error() message will tell us what was wrong with our query, similar to the message we would receive at the MySQL console.

14. What is Constructors and Destructors?
CONSTRUCTOR : PHP allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
DESTRUCTORS : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.



15. Explain the visibility of the property or method.
The visibility of a property or method must be defined by prefixing the declaration with the keywords public, protected or private.
Class members declared public can be accessed everywhere.
Members declared protected can be accessed only within the class itself and by inherited and parent classes.
Members declared as private may only be accessed by the class that defines the member.



16. What are the differences between Get and post methods.
There are some defference between GET and POST method
1. GET Method have some limit like only 2Kb data able to send for request
But in POST method unlimited data can we send
2. when we use GET method requested data show in url but
Not in POST method so POST method is good for send sensetive request


17. What are the differences between require and include?
Both include and require used to include a file but when included file not found
Include send Warning where as Require send Fatal Error


18.  What is use of header() function in php ?
The header() function sends a raw HTTP header to a client.We can use herder()
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen.

19. List out the predefined classes in PHP?
Directory
stdClass
__PHP_Incomplete_Class
exception
php_user_filter


20. What type of inheritance that PHP supports?
In PHP an extended class is always dependent on a single base class,that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'.

21. How can we encrypt the username and password using php?
You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password");
We can encode data using base64_encode($string) and can decode using base64_decode($string);


22. What is the difference between explode and split?
Split function splits string into array by regular expression. Explode splits a string into array by string.
For Example:explode(" and", "India and Pakistan and Srilanka");
 split(" :", "India : Pakistan : Srilanka");
Both of these functions will return an array that contains India, Pakistan, and Srilanka.


23. How do you define a constant?
Constants in PHP are defined using define() directive, like define("MYCONSTANT", 100);

24. How do you pass a variable by value in PHP?
Just like in C++, put an ampersand in front of it, like $a = &$b;

25. What does a special set of tags <?= and ?> do in PHP?
 The output is displayed directly to the browser.

26. How do you call a constructor for a parent class?
 parent::constructor($value)

27. What’s the special meaning of __sleep and __wakeup?
__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

28. What is the difference between PHP and JavaScript?
javascript is a client side scripting language, so javascript can make popups and other things happens on someone’s PC. While PHP is server side scripting language so it does every stuff with the server.

29. What is the difference between the functions unlink and unset?
unlink() deletes the given file from the file system.
unset() makes a variable undefined.


30. How many ways can we get the value of current session id?
session_id() returns the session id for the current session.

31. What are default session time and path?
default session time in PHP is 1440 seconds or 24 minutes
Default session save path id temporary folder /tmp


32. for image work which library?
we will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.

33. How can we get second of the current time using date function?
<?php
$second = date(“s”);
?>


34. What are the Formatting and Printing Strings available in PHP?
printf()-    Displays a formatted string
sprintf()-Saves a formatted string in a variable
fprintf()    -Prints a formatted string to a file
number_format()-Formats numbers as strings

35. How can we find the number of rows in a result set using PHP?
$result = mysql_query($sql, $db_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";


Read more....

Pagination Issue in Codeigniter [solved]

There is many students face problem in Pagination library in CI
CodeIgniter

Please update the following code and your problem resolved


public function index($index=1)
    {
        $per_page=2;   // set accorrding to requiremnet
       if($index==1){
           $index=0;
       }
         
         $this->load->model("MODLE_NAME");
            $user_data['user_data']=$this->Model_name->select($per_page,$index);
            $t=$this->Model_name;
            $table_name=$t::table_name;
            $query = $this->db->get($table_name);
            $row_count=$query->num_rows();
   // pagination     
       $this->load->library('pagination');

            $config['base_url'] = base_url().'admin/controller_function/index/';
            $num_rows_pagination=$row_count;
            $config['total_rows'] = $num_rows_pagination;
            $config['per_page'] = $per_page;
             $config['uri_segment'] = 4;
               // pagination formating
                    $config['full_tag_open'] = "<br><ul class='pagination'>";
                    $config['full_tag_close'] ="</ul>";
                    $config['num_tag_open'] = '<li>';
                    $config['num_tag_close'] = '</li>';
                    $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
                    $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
                    $config['next_tag_open'] = "<li>";
                    $config['next_tagl_close'] = "</li>";
                    $config['prev_tag_open'] = "<li>";
                    $config['prev_tagl_close'] = "</li>";
                    $config['first_tag_open'] = "<li>";
                    $config['first_tagl_close'] = "</li>";
                    $config['last_tag_open'] = "<li>";
                    $config['last_tagl_close'] = "</li>";
            
            $this->pagination->initialize($config); 
            $user_data['pagination']= $this->pagination->create_links();
            $user_data['total_row']=$row_count;
            $user_data['page'] = 'controller_function';
        $this->load->view('admin/Manage/view_page',$user_data);   // Customize according its to view panel
       
   }
 
                           //---------------WARNING------------ 
 
//================= YOUR MODEL and Controller According to your Project ================ 
Read more....

Monday, April 6, 2015

validation for web URL and Email

This is code for validation for web URL and Email

use this page as is it and get your full Validation Page 

like and share

 follow on  github


 
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>validate email and url</title>
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<style>
.error{
font-family: cursive;
font-size: 10px;
color: red;
margin-bottom: 10px;
}
</style>
</head>
<body id="html_body">
<div class="row" style="padding: 5px;margin: 2px;">
<div class="step2 col-md-12" style="margin-bottom:10px">
<div class="heading"><h2><strong> Check Email and url </strong></h2></div>
<form action="" method="post" id="register-form" novalidate="novalidate">
<div class="content col-md-12" style="border: solid 1px #eaeaea;padding: 10px;">
<div class="content col-md-12">
<div class="form-group col-md-12" >
<label for="width" class="col-sm-4" >Email-Id</label>
<div class="col-sm-8" >
<input type="email" name="emailid" class="form-control" id="email" placeholder="admin@php999.com " required="required">
</div>
</div>
<div class="col-sm-8 col-sm-offset-4 error email"></div>
</div>
<div class="content col-md-12">
<div class="form-group col-md-12" >
<label for="width" class="col-sm-4" >Website</label>
<div class="col-sm-8" >
<input type="text" name="website" class="form-control" id="website" placeholder="www.php999.blogspot.in " required="required">
</div>
</div>
<div class="col-sm-8 col-sm-offset-4 error website"></div>
</div>
</div>
</form>
</div>
<div class="content col-md-12">
<div class="col-md-3" style="float:right;">
<button class="btn" style="background-color:#fe8409;" id="get-code" type="" name="preview">GET CODE!</button>
</div>
</div>
<div class="col-md-12" id="html-block" style="margin:10px;display:none">
<textarea id="html-content" rows="8" cols="55"></textarea>
</div>
</div>
<script>
$('#get-code').click(function(e){
var email = $('#email').val();
var email_status=validateEmail(email);
// alert("email_status="+email_status);
var website = $('#website').val();
// alert(website);
var website_status=validateWeb(website);
// alert("website_status="+website_status);
if(email_status==false){
$('.email').html('Please enter your a valid email address...');
} else if(website_status==false){
$('.website').html('Please enter a valid url ');
} else {
$('.email').html('');
$('.website').html('');
// alert("tick tok");
var htmlcode = $('#html_body').html();
$('#html-content').val(htmlcode);
$('#html-block').css('display','block');
e.preventDefault();
}
});
</script>
<script>
function validateEmail(email){
var emailReg = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
var valid = emailReg.test(email);
if(!valid) {
return false;
} else {
return true;
}
}
function validateWeb(web){
var webReg = new RegExp(/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:[\w-]*)\.\w{2,}$/);
//var webReg = new RegExp(/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:[\w-]*)\.\w{2,}$);
var valid = webReg.test(web);
if(!valid) {
return false;
} else {
return true;
}
}
</script>
<div class="row">
<span class="glyphicon glyphicon-barcode"> 2015&COPY; himmsrathore | <a target="_blank" href="http://php999.blogspot.in">php999 </a></span></div>
</body>
//  
</html>
 
 
Read more....

Saturday, April 4, 2015

How can I prevent SQL-injection in PHP?

How can I prevent SQL-injection in PHP?

Use prepared statements and parameterized queries.

<?php
// Using PDO:

    $stmt = $pdo->prepare('SELECT * FROM Table_name WHERE uname = :uname');

    $stmt->execute(array('uname' => $name));

    foreach ($stmt as $row) {
        // do something with $row
    }

//    Using MySQLi:

    $stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?');
    $stmt->bind_param('s', $name);

    $stmt->execute();

    $result = $stmt->get_result();
    while ($row = $result->fetch_assoc()) {
        // do something with $row
    }
?>

Correctly setting up the connection

Note that when using PDO to access a MySQL database real prepared statements are not used by default. To fix this you have to disable the emulation of prepared statements. An example of creating a connection using PDO is:

                                                                                           
                                                                                           
$dbConnection = new PDO('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8', 'user', 'pass');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);                            
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);                    
                                                                                           
                                                                                           
 
In the above example the error mode isn't strictly necessary, but it is advised to add it. This way the script will not stop with a Fatal Error when something goes wrong. And it gives the developer the chance to catch any error(s) which are thrown as PDOExceptions.
What is mandatory however is the first setAttribute() line, which tells PDO to disable emulated prepared statements and use real prepared statements. This makes sure the statement and the values aren't parsed by PHP before sending it to the MySQL server (giving a possible attacker no chance to inject malicious SQL).
Although you can set the charset in the options of the constructor, it's important to note that 'older' versions of PHP (< 5.3.6) silently ignored the charset parameter in the DSN.

Explanation

What happens is that the SQL statement you pass to prepare is parsed and compiled by the database server. By specifying parameters (either a ? or a named parameter like :name in the example above) you tell the database engine where you want to filter on. Then when you call execute, the prepared statement is combined with the parameter values you specify.
The important thing here is that the parameter values are combined with the compiled statement, not an SQL string. SQL injection works by tricking the script into including malicious strings when it creates SQL to send to the database. So by sending the actual SQL separately from the parameters, you limit the risk of ending up with something you didn't intend. Any parameters you send when using a prepared statement will just be treated as strings (although the database engine may do some optimization so parameters may end up as numbers too, of course). In the example above, if the $name variable contains 'Sarah'; DELETE FROM employees the result would simply be a search for the string "'Sarah'; DELETE FROM employees", and you will not end up with an empty table.
Another benefit with using prepared statements is that if you execute the same statement many times in the same session it will only be parsed and compiled

 

Read more....
Related Posts Plugin for WordPress, Blogger...