Collection of Important Dynamic Web Programming languages Ebooks

Hello Geeks! - you know i already have Collection of important Programming languages ebooks, but that is Software + Web App programming ebooks and after posting "How to become Web Programmer complete guide for beginners" many readers requested me to upload Dynamic Web Programming languges ebooks. In this post i've covered "AJAX, ASP.NET, Coldfusion, Perl, PHP, Ruby and Ruby on Rails Ebooks - Free giveaway.

Note : We've compressed Ebooks in ZIP format (99% Virus Free) Mediafire Download Links - Just Click on Ebook name & Download instantly. Thank you


I. AJAX (Asynchronous JavaScript and XML)



II. ASP (Advance Static Pages)



III. Coldfusion



IV. Perl



V. PHP (HyperText Preprocessor)

VI. Ruby


VII. Ruby on Rails



Thank you for reading my post, And if any link is broken feel free to comment and let me know your problem. You can also request any other Programming e-books (We'll upload it Asap!) If you like it please do a share to increase us.

How to become Web Programmer Guide for Beginners

Hello, Geeks! today m feeling little energetic and inspired so i thought to share little guide as per my experience and knowledge, well m not Professional Web Programmer - but here i got many tips, guides, tutorials to start learning Web programming language by Professional Programmers like my Sir (Teacher) in my Institute. From past couple of days I'm collecting information about How to start learning Web Programming language and it is totally for Beginners only.


How to start learning Web Programming Lang.

There are many types of Web Programming language being used by the Web Application but you've to start from the most basic Markup language and that is HTML commonly known as Hyper Text Markup language (HTML 5). HTML is very easy and interesting to learn, HTML is almost used by every Web Site & Web Application. After then move to  Dynamic Web Programming languages like JavaScript, AJAX, PHP, ASP etc. And the most  important thing I want to explain you that Programming just can't be learn by reading or  memorizing it - Programming is like body building the more you build the more you get  Stronger - (Hack w0rm). Try to create your own Web Page & App using  Dreamweaver, & test it in Local Host Server etc I'll elaborate more deeply in this Post.


First of all lemme explain you difference between Static & Dynamic Web Pages :

Static : Static pages are the generic .html files usually relegated to FAQs, contact information, Blog Articles etc. HTML is Static : Listen suppose you create an application that Says Hello World!, then anyone can able to see your code using Web Browser (Source Code) because you code is in .HTML and that is Static.

Dynamic : Dynamic Pages are really interesting and little protected, Nowadays almost every Web Site is using Dynamic Pages like (.asp, .jsp, .php, etc), You can't see the code of Dynamic Pages like you can see the code of .HTML. Usually all programmers use Dynamic Pages to generate Static Codes. For Example you create an application like search engine then you've to connect PHP/ASP page into action - well you can also use Static but it isn't like Dynamic. You can't simply see the code of .PHP action file.


Steps to get Started with Web Programming :

*Go through below stage and learn step by step :

1. HTML (Markup Language) : Folks! I want your base to be strong, If you know complete HTML 5 then it would be easy to learn another second stage Languages. HTML is Markup language which comes under Static Web Page. If you're beginner in Web Programming start with HTML.

2. CSS : Cascading Style Sheets is very easy Static Language. CSS is used for designing, fonts, lighting text, effects and whatever that makes your Web Site looks little attractive. CSS can be learnt in just 7 Days! Its pretty small and easy with lots of enjoyment. CSS only got a job of designing, Flash, Adding image effects, Font effects, Color, Application designing etc.

3. JavaScript : Commonly Javascript is used in every Web Sites, Javascript is Dynamic Web Programming language. If you're champ in HTML & CSS then it would be easy to learn Javascript easily. Javascript have an important role in Web Applications, Javascript is very intersting with lots of fun also.

4. AJAX : Now after completing Javascript move to most adorable programming language called AJAX : (Asynchronous JavaScript and XML) AJAX is a novel programming approach to web applications that creates the experience of “fat client” applications using lightweight JavaScript and XML technologies.

5. PHP/ASP : It's time to move on more advance Dynamic Web Programming language likes PHP or ASP. Both have an unbeatable competion but I'll recommend you to learn PHP. PHP (Hypertext Preprocessor) is very interesting dynamic  language. It isn't tough until you know HTML, Javascript etc. PHP is one my mine favorite Programming language.


Now, after learning 5 most important Web Programming languages : HTML, CSS, Javascript, AJAX, PHP. You can move to advance Web Programming languages like Ruby, Ruby on Rails, Visual Basic Web App Dev, C#, .NET, etc. But before doing all these advance please become champ in all that five Programming languages.

How to learn Web Programmnig Languages : (Methods to learn)

To learn Web Programming languages you'll require atleast 2 hour daily practice, refresh your skills everday and think how it works, what is the main conclusion. And go through below Guide to learn Programming easily.


The First Step : If you're going through my guide and learning that five programming languages sequencely then i'll recommend you to start with HTML. While learning HTML create one word file of all HTML Tags, with two line comments and defination of defined Tag. CSS doesn't have any heavy contents like Tag, scripts etc.. it's simply. JavaScript can give you little tough challenge, take your time to learn it slowly don't do rush and never skip any contents saying that i'll do it later, always try to challenge yourself with Programming. AJAX and PHP have coplicated contents, but if you learn sequencely and go on smoothly then it would be easy for you to learn PHP and AJAX.

Always take Tea/Coffee : While practicing and creating some Application with my own, sometimes my brain gets buzzed! that is why i always keep Coffee near to my Computer table. In programming you've to think and create it wisely, so you can impress yourself, public or your Boss/Teacher. But I'm not only recommending you to take Tea or Coffee only - Well mine some friends drink Mountain Dew, Red Bull etc. It will keep your mind cool and little fresh.

Download Dreamweaver CS6 : Adobe Dreamweaver CS6 is one the best Web Application Development Software commonly used by all Web Programmer.  Dreamweaver is easy to use with all types of Static, Dynamic web programming language. It will help you a lot to learn Web Programming and create Web App easily.


How Stuffs work : The main thing in programming is to think and understand how Web Application is working. While learning someguys just memorize Programming tags, scripts and codes , but when it comes to creating and facing an errors they just become BLANK!. Whenever you learn any programming language please always try to understand How it is working, and Visualize its structure & flow in your mind.

Web App Note : When I was pursuing my diploma they always tell us to keep a note of everything what you learn, In case you forget some programming codes or stucked into problem - your Note can remind you the solution. I m not saying to write all things whatever you learn, but just create atleast one note on Hard Stuffs.


How to test Programmed Web Page & Application ?

While learning HTML, JavaScript etc you'll need to test your Program wheather it is working correctly or not? - checking for any Error or Mistakes. So you'll need a Web Server to test Static and Dynamic Web Applications, Therefore i recommend you to download WAMP Server and Install it in your Computer, Start WAMP Server, Go to C:\wamp\www\ and paste your web page file in that folder, now open your browser and type localhost or 127.0.0.1 - Hit enter and you can access your Web Application on offline mode with all HTTP features.

From where Should I learn ?

This is the most common problem faced by learners, they don't get source to get started with simple example and tutorials, But I say if you've curiosity to learn and passion to do something then you can even learn just from an E-book. The best way to learn Programming is to Download E-books, Purchase Web Programming languages Books, Learn from W3Schools, Google your Queries, Try to understand How it works.

There are a lots of Ebooks on internet for Beginners to learn Web Programming languages. Click here to download some ebooks from our blog.


Web Programmers
              In this Era of Internet and technologies, Web Programmers are growing with lots of IT Skills, and Knowledge. well this is a tough Competion for guy like me and you who is interested in Hacking, Programming and other Computer Skills. As fast the IT (Information Technology) is growing the demand of Web Programmer, Computers Programmers are growing. Web Programming is one of the best future carrer option.

Other Tips to learn Web Programming Languages :

* Friends, Curiosity is the best way to learn anything
* Be Passionate and Confident while Learning
* Always test your Web Application in Local Server
* Learn from your mistakes, find an error and fix it
* Always use Google to clear your doubts.
* And always Stay connected with Bolt Geeks.


Thank you for reading my post, This is small guide by Vivek,I hope you enjoyed this post. Feel free to ask any doubt and lemme know your problem. If you liked it please share it to increase us.

Difference between stored procedures and user defined functions


2. Named Batches: Set of T-SQL statements can written and executed as a single unit with a proper name called Named batch. These includes

  1. Stored procedures
  2. User defined Functions
  3. Triggers

  1. Stored Procedures: Stored procedures are one of the database objects. There are two types of stored procedures available in SQL Server.

    1. System Defined Stored Procedures
    2. User Defined Stored Procedures

System Defined Stored Procedures: These are also known as predefined or built-in stored procedures.

E.g.: 
SP_HELP
SP_RENAMEDB
SP_RENAME
SP_HELPCONSTRAINT
SP_HELPTEXT
------
-----
-------

User Defined Stored Procedures: Procedures created by the user are called used defined stored procedures.

Syntax:
 CREATE PROC [EDURE] PROCEDURENAME
            [@PARA 1 DATATYPE (SIZE)[=DEFAULT_VALUE][OUTPUT]
            @PARA 2 DATATYPE (SIZE)[=DEFAULT_VALUE][VALUE],….]
AS
BEGIN
SELECT STATEMENT
END

Syntax to execute the user defined stored procedure:
EXEC [UTE] PROCEDURENAME [VALUE1,VALUE2,…]

Note: The number of values supplied through EXEC statement must be equal to the number parameters.



E.g.1: Write a procedure to select the data from EMP table.

CREATE PROCEDURE P1
AS
BEGIN
SELECT * FROM EMP
END

      EXEC P1

E.g.2: Write a procedure to select the data from EMP table based on user supplied DEPTNO.

CREATE PROCEDURE P2 @X INT
AS
BEGIN
SELECT * FROM EMP WHERE DEPTNO=@X
END

EXEC P2 20






E.g.3: Write a procedure to add two numbers

CREATE PROCEDURE P3 @A INT=10,@B INT=20
AS
BEGIN
DECLARE @C INT
SET @C=@A+@B
PRINT @C
END

EXEC P3
Output: 30
EXEC P3 25, 45
Output: 70

Note: Server will give highest priority to the user supplied values rather than default values.



USER DEFINED FUNCTIONS: Functions created by user are called user defined functions

Types of user defined functions:
1.      SCALAR VALUED FUNCTIONS
2.       TABLE VALUED FUNCTIONS

Scalar valued functions: These functions will return a scalar value to the calling environment
Syntax:
 CREATE FUNCTION < FUNCTION_NAME> (@PARA 1 DATA TYPE ,
@ PARA 2 DATATYPE ,…..)
RETURNS <DATATYPE>
AS
BEGIN
DECLARE  @VARIABLE  DATATYPE
--------
----------
RETURN  @VARIABLE
END

Syntax to execute the user defined function:
SELECT/PRINT DBO.FUNCTIONNAME (VALUE1,VALUE2,……….)

Note: The number of values supplied through PRINT/SELECT statement must be equal to the number parameters.


E.g.1: Write a function to find the product of two numbers

 CREATE FUNCTION F1 (@ A INT, @B INT)
 RETURNS INT
 AS
BEGIN
DECLARE @ C INT
SET @C = @A * @B
RETURN @C
END

SELECT/PRINT DBO.F1 (3,5)


E.g.2: Write function to find the net salary of an employee read  EMPNO though parameter and display the net to return value
 CREATE FUNCTION F2 (@ VNO INT)
            RETURNS  INT
            AS
BEGIN
            DECLARE @ VSAL INT, @VCOM INT, @NET INT
            SELECT @VSAL =  SAL, @VCOM=COM
FROM EMP WHERE EMPNO =@VNO
IF @ VCOM IS NULL
BEGIN
PRINT ‘COMMISION IS NULL’
SET @NET = @VSAL
END
ELSE
BEGIN
SET @ NET = @VSAL + @VCOM
END
RETURN (@NET)
END

PRINT/SELECT DBO.F2(22)








2) Table valued function: These functions will return entire table to the calling environment.

Syntax:
CREATE FUNCTION <FUNCTION_NAME>(PARA 1 DATA TYPE ……….)
RETURNS TABLE
AS
BEGIN
<FUNCTION BODY>
RETURN (SELECT STATEMENT)
END

E.g.1: Write a function to return entire dept table
CREATE FUNCTION F3()
RETURNS TABLE
AS
BEGIN
RETURN (SELECT * FROM DEPT)
END




SELECT * FROM F3()
DEPT
DNAME
LOC







E.g2:
CREATE FUNCTION F4()
RETURN TABLE
AS BEGIN
RETURN(SELECT ENAME, DNAME FROM EMP, DEPT
                      WHERE EMP.DEPTNO = DEPT.DEPTNO)
END
SELECT * FROM F4()
ENAME                                 DNAME
SMITH                        RESEARCH
MILLER                     ACCOUNTING

Creating jQuery Popup

Jquery popup is extremely popular effect for websites, as a web developer or designer we can apply this effects very easy in our projects, we can search and download, using third party jQuery plugins. If your wonder on how to create popup div in your own hand. In this article i would like to share, on how to create a pop up div, effect using the popular jQuery library.


In this jquery example / tutorial we create jquery popup div in ‘click trigger’ event, it pop up displays with opacity background and it will remains center the popup if you scrolling zoom out the browser and closing it fadeout, and also you can customize the content of the popup div. Let’s begin

1. Creating the Page Template

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Creating Popup Div | istockphp.com</title>
<link href="style/style.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> </script>
<script type="text/javascript" src="js/script.js"></script>
</head>

<body>
 <a href="#" class="topopup">Click Here Trigger</a>

    <div id="toPopup">

        <div class="close"></div>
        <span class="ecs_tooltip">Press Esc to close <span class="arrow"></span></span>
  <div id="popup_content"> <!--your content start-->
            <p>netus et malesuada fames ac turpis egestas. </p>
            <p align="center"><a href="#" class="livebox">Click Here Trigger</a></p>
        </div> <!--your content end-->

    </div> <!--toPopup end-->

 <div class="loader"></div>
    <div id="backgroundPopup"></div>
</body>
</html>



In index.html, we include the css, jQuery and js script after the title tag; in the body we have 3 div containers for popup div event.

div container for loading
div container for popup background,
and div container for popup
2. The stylesheet

style.css

#backgroundPopup {
    z-index:1;
    position: fixed;
    display:none;
    height:100%;
    width:100%;
    background:#000000;
    top:0px;
    left:0px;
}
#toPopup {
    font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
    background: none repeat scroll 0 0 #FFFFFF;
    border: 10px solid #ccc;
    border-radius: 3px 3px 3px 3px;
    color: #333333;
    display: none;
    font-size: 14px;
    left: 50%;
    margin-left: -402px;
    position: fixed;
    top: 20%;
    width: 800px;
    z-index: 2;
}
div.loader {
    background: url("../img/loading.gif") no-repeat scroll 0 0 transparent;
    height: 32px;
    width: 32px;
    display: none;
    z-index: 9999;
    top: 40%;
    left: 50%;
    position: absolute;
    margin-left: -10px;
}
div.close {
    background: url("../img/closebox.png") no-repeat scroll 0 0 transparent;
    cursor: pointer;
    height: 30px;
    position: absolute;
    right: -27px;
    top: -24px;
    width: 30px;
}
span.ecs_tooltip {
    background: none repeat scroll 0 0 #000000;
    border-radius: 2px 2px 2px 2px;
    color: #FFFFFF;
    display: none;
    font-size: 11px;
    height: 16px;
    opacity: 0.7;
    padding: 4px 3px 2px 5px;
    position: absolute;
    right: -62px;
    text-align: center;
    top: -51px;
    width: 93px;
}
span.arrow {
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 7px solid #000000;
    display: block;
    height: 1px;
    left: 40px;
    position: relative;
    top: 3px;
    width: 1px;
}
div#popup_content {
    margin: 4px 7px;
    /* remove this comment if you want scroll bar
    overflow-y:scroll;
    height:200px
    */
}




In the css, if you want scrollbar in the popup just remove comment in line 74.

3. The jQuery script

script.js

jQuery(function($) {

 $("a.topopup").click(function() {
   loading(); // loading
   setTimeout(function(){ // then show popup, deley in .5 second
    loadPopup(); // function show popup
   }, 500); // .5 second
 return false;
 });

 /* event for close the popup */
 $("div.close").hover(
     function() {
      $('span.ecs_tooltip').show();
     },
     function () {
         $('span.ecs_tooltip').hide();
       }
    );

 $("div.close").click(function() {
  disablePopup();  // function close pop up
 });

 $(this).keyup(function(event) {
  if (event.which == 27) { // 27 is 'Ecs' in the keyboard
   disablePopup();  // function close pop up
  }
 });

        $("div#backgroundPopup").click(function() {
  disablePopup();  // function close pop up
 });

 $('a.livebox').click(function() {
  alert('Hello World!');
 return false;
 });

  /************** start: functions. **************/
 function loading() {
  $("div.loader").show();
 }
 function closeloading() {
  $("div.loader").fadeOut('normal');
 }

 var popupStatus = 0; // set value

 function loadPopup() {
  if(popupStatus == 0) { // if value is 0, show popup
   closeloading(); // fadeout loading
   $("#toPopup").fadeIn(0500); // fadein popup div
   $("#backgroundPopup").css("opacity", "0.7"); // css opacity, supports IE7, IE8
   $("#backgroundPopup").fadeIn(0001);
   popupStatus = 1; // and set value to 1
  }
 }

 function disablePopup() {
  if(popupStatus == 1) { // if value is 1, close popup
   $("#toPopup").fadeOut("normal");
   $("#backgroundPopup").fadeOut("normal");
   popupStatus = 0;  // and set value to 0
  }
 }
 /************** end: functions. **************/
}); // jQuery End


In the click event we triggered the 'loading()' function and delay .5 second and triggered the loadPopup(), and same for close trigger, we add little more for closing the popup, if hover the ‘Close’ the tool tip message will triggered and keyboard event for close.

4. Done

Wer’e done, we learn one of jquery sample on creating our own popup div using jQuery, you can edit the content of the popup like adding text or form. Let’s have a look at what we’ve achieved:

We create popup div without third party plugin
Works in old IE browser, IE 7,8
We add little feature, hover tool tip and keyboard event
If you enjoyed this article, please consider sharing it!

How To create Widget In Wordpress

In this tutorial, we will create a simple widget that just greets visitors. Take a look at this code and then paste it in your site-specific plugin to see it in action.


// Creating the widget 
class wpb_widget extends WP_Widget {

function __construct() {
parent::__construct(
// Base ID of your widget
'wpb_widget', 

// Widget name will appear in UI
__('WPBeginner Widget', 'wpb_widget_domain'), 

// Widget description
array( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ) 
);
}

// Creating widget front-end
// This is where the action happens
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];

// This is where you run the code and display the output
echo __( 'Hello, World!', 'wpb_widget_domain' );
echo $args['after_widget'];
}
  
// Widget Backend 
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'wpb_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php 
}
 
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // Class wpb_widget ends here

// Register and load the widget
function wpb_load_widget() {
 register_widget( 'wpb_widget' );
}
add_action( 'widgets_init', 'wpb_load_widget' );

/*---------------------------------------------------------------*/

Now go to Appearance » Widgets, drag and drop WPBeginner Widget in your sidebar to see this custom widget in action.
Simple wasn’t it? First we created a custom widget. Then we defined what that widget does and how to display the widget back-end. Then we defined how to handle changes made to widget. Lastly, we registered and loaded the widget.


Import Gmail contacts using PHP


In this tutorial, we can import Gmail contacts using PHP.
Kindly follow below steps.


  <?php   error_reporting(E_ALL);   $user = "Your Gmail ID"; // Enter your gmail ID   $password = "Your Gmail Password"; // Enter your Gmail account password.       // ref: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html       // step 1: login   $login_url = "https://www.google.com/accounts/ClientLogin";   $fields = array(   'Email' => $user,   'Passwd' => $password,   'service' => 'cp', // <== contact list service code   'source' => 'test-google-contact-grabber',   'accountType' => 'GOOGLE',   );       $curl = curl_init();   curl_setopt($curl, CURLOPT_URL,$login_url);   curl_setopt($curl, CURLOPT_POST, 1);   curl_setopt($curl, CURLOPT_POSTFIELDS,$fields);   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   $result = curl_exec($curl);       $returns = array();       foreach (explode("\n",$result) as $line)   {   $line = trim($line);   if (!$line) continue;   list($k,$v) = explode("=",$line,2);       $returns[$k] = $v;   }       curl_close($curl);       // step 2: grab the contact list   $feed_url = "http://www.google.com/m8/feeds/contacts/$user/full?alt=json&max-results=250";       $header = array(   'Authorization: GoogleLogin auth=' . $returns['Auth'],   );       $curl = curl_init();   curl_setopt($curl, CURLOPT_URL, $feed_url);   curl_setopt($curl, CURLOPT_HTTPHEADER, $header);   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);       $result = curl_exec($curl);   curl_close($curl);       $data = json_decode($result);       $contacts = array();       foreach ($data->feed->entry as $entry)   {   $contact = new stdClass();   $contact->title = $entry->title->{'$t'};   $contact->email = $entry->{'gd$email'}[0]->address;   $contacts[] = $contact;   }   echo "<pre>";   print_r($contacts);

PHP CLOSING TAG TIPS


The PHP closing tag?> ) on a PHP document is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. I think you have faced this frustrating issues and had to waste your valuable time to debug. For this reason, all PHP files shouldOMIT the closing PHP tag, and instead use a comment block to mark the end of file and it’s location relative to the application root. This allows you to still identify a file as being complete and not truncated. Here is an example:
BAD PRACTICE:
1<?php 
2echo "Here's my code!"
3?>
GOOD PRACTICE:
1<?php 
2echo "Here's my code!";
Also, while using php code into html pages it is not recommended that you use php short form (<? ?>) because this may not support if it is configured in the php.ini. So, if you use this and found your application is not working and in the same time you can’t modify the php.ini then you have to change those which will kill lots of your time! So best is always use:

Get information about your memory usage using PHP


Get information about your memory usage using PHP.
In order to optimize your scripts, you may definitely want to know how many amount of RAM they use on your server. This snippet will check memory and then print initial, final and peak usages.

PHP Code :-
<?php   echo "Initial: ".memory_get_usage()." bytes \n"; /* prints Initial: 361400 bytes */   // let's use up some memory for ($i = 0; $i < 100000; $i++) { $array []= md5($i); }   // let's remove half of the array for ($i = 0; $i < 100000; $i++) { unset($array[$i]); }   echo "Final: ".memory_get_usage()." bytes \n"; /* prints Final: 885912 bytes */   echo "Peak: ".memory_get_peak_usage()." bytes \n"; /* prints Peak: 13687072 bytes */   ?>

Optimize Code In Php(Code Optimization)

Select COUNT() will be faster than mysql_num_rows(), internally the server will process the request differently. mysql_query() transfers all result records from the MySQL into the php process before it returns. That alone would make the mysql_num_rows() version slower. Furthermore for some engines MySQL can serve a Count(*) request from the index of the table without hitting the actual data. A SELECT * FROM foo on the other hand results in a full table scan and MySQL has to read every single dataset 

<?php // The better way , it will be faster $sql = “select count(id) from user where email like’%gmail%’”; $res = mysql_query($sql) or die(mysql_error()); echo $value = mysql_fetch_row($res);   // it will be slower $sql = “select count(id) from user where email like’%gmail%’”; $res = mysql_query($sql) or die(mysql_error()); echo $value = mysql_num_rows($res);   ?>   <?php //Example ONE     for($i = 0; $i < count($myLargeArray); $i++ ) { echo myLargeArray[$i]; }   //Example TWO   $count = count($myLargeArray); for($i = 0; $i < $count; $i++ ) { echo myLargeArray[$i]; }   ?>

How to Import the contents of CSV files into MySQL Database using PHP


Step1: create a database with name test and create table user
Step2: Put a csv file (which you want to import) into your document
root.
Step3: Established database connection and first open the file in read
mode, using fgets () all data will be collected in an array and that
array will be stored in database.
Create user table:

CREATE TABLE IF NOT EXISTS `user` ( `ID` int(10) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `email` varchar(50) NOT NULL, PRIMARY KEY (`ID`) )

Code For csv-import.php:

<?php   $connect = mysql_connect('hostname','username','password'); if (!$connect) { die('Could not connect to MySQL: ' . mysql_error()); }   $cid =mysql_select_db('test',$connect); // supply your database name   define('CSV_PATH','C:/xampp/htdocs/csvfile/'); // path where your CSV file is located   $csv_file = CSV_PATH . "infotuts.csv"; // Name of your CSV file $csvfile = fopen($csv_file, 'r'); $theData = fgets($csvfile); $i = 0; while (!feof($csvfile)) { $csv_data[] = fgets($csvfile, 1024); $csv_array = explode(",", $csv_data[$i]); $insert_csv = array(); $insert_csv['ID'] = $csv_array[0]; $insert_csv['name'] = $csv_array[1]; $insert_csv['email'] = $csv_array[2]; $query = "INSERT INTO csvdata(ID,name,email) VALUES('".$insert_csv[ID]."','".$insert_csv['name']."','".$insert_csv   ['email']."')"; $n=mysql_query($query, $connect ); $i++; } fclose($csvfile);   echo "File data successfully imported to database!!"; mysql_close($connect); ?>



How To Protect your PHP Script by hiding the extensions


A few simple techniques can help to hide PHP, possibly slowing down an attacker who is attempting to discover weaknesses in your system. By setting expose_php to off in your php.ini file, you reduce the amount of information available to them. Another techniques is to configure web servers such as apache to parse different filetypes through PHP, either with an .htaccess directive, or in the apache configuration file itself. You can then use misleading file extensions:
Example (1): Hiding PHP as another language
#write below code in .htaccess
# Make PHP code look like other code types
AddType application/x-httpd-php .asp
From Above Technique you must have to use yourfilename.asp for run your
php File.
In above Example you can use any unknown type by replacing .asp with
another like wise .amp , .html , .htm or etc.
Example (2): By setting expose_php to off in your php.ini file
modify below Files :
httpd.conf
————-
# …
# Minimize ‘Server’ header information
ServerTokens Prod
# Disable server signature on server generated pages
ServerSignature Off
# …
# Set default file type to PHP
DefaultType application/x-httpd-php
# …
php.ini
————
; …
expose_php = Off
; …
Now the URLs will look like this:
http://websitename/forums/post?id=15
Check Above URL .php missing
Now hacker knows only that you are using Apache.

How To Create a Zip File Using PHP


Creating .ZIP archives using PHP can be just as simple as creating them on your desktop. PHP’s ZIP class provides all the functionality you need! To make the process a bit faster for you, I’ve coded a simple create_zip function for you to use on your projects.
The PHP
/* creates a compressed zip file */

function create_zip($files = array(),$destination = '',$overwrite = false) {

//if the zip file already exists and overwrite is false, return false

if(file_exists($destination) && !$overwrite) { return false; }

//vars

$valid_files = array();

//if files were passed in...

if(is_array($files)) {

//cycle through each file

foreach($files as $file) {

//make sure the file exists

if(file_exists($file)) {

$valid_files[] = $file;

}

}

}

//if we have good files...

if(count($valid_files)) {

//create the archive

$zip = new ZipArchive();

if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {

return false;

}

//add the files

foreach($valid_files as $file) {

$zip->addFile($file,$file);

}

//debug

//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;

//close the zip -- done!

$zip->close();

//check to make sure the file exists

return file_exists($destination);

}

else

{

return false;

}

}

Sample Usage

$files_to_zip = array(

'preload-images/1.jpg',

'preload-images/2.jpg',

'preload-images/5.jpg',

'kwicks/ringo.gif',

'rod.jpg',

'reddit.gif'

);

//if true, good; if false, zip creation failed

$result = create_zip($files_to_zip,'my-archive.zip');  //Pass names here.
         
The function accepts an array of files, the name of the destination files, and whether or not you’d like the destination file to be overwritten if a file of the same name exists. The function returns true if the file was created, false if the process runs into any problems.

Cookie Vs Sessions


A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Both cookies and sessions are available to you as a PHP developer, and both accomplish much the same task of storing data across pages on your site. However, there are differences between the two that will make each favorable in their own circumstance.
Cookies can be set to a long lifespan, which means that data stored in a cookie can be stored for months if not years. Cookies, having their data stored on the client, work smoothly when you have a cluster of web servers, whereas sessions are stored on the server, meaning in one of your web servers handles the first request, the other web servers in your cluster will not have the stored information.
Sessions are stored on the server, which means clients do not have access to the information you store about them – this is particularly important if you store shopping baskets or other information you do not want you visitors to be able to edit by hand by hacking their cookies. Session data, being stored on your server, does not need to be transmitted with each page; clients just need to send an ID and the data is loaded from the local file. Finally, sessions can be any size you want because they are held on your server, whereas many web browsers have a limit on how big cookies can be to stop rogue web sites chewing up gigabytes of data with meaningless cookie information.
So, as you can see, each have their own advantages, but at the end of the day it usually comes down one choice: do you want your data to work when you visitor comes back the next day? If so, then your only choice is cookies – if you have any particularly sensitive information, your best bet is to store it in a database, then use the cookie to store an ID number to reference the data. If you do not need semi-permanent data, then sessions are generally preferred, as they are a little easier to use, do not require their data to be sent in entirety with each page, and are also cleaned up as soon as your visitor closes their web browser.
- See more at: http://blog.hirephp.com/php/cookie-vs-sessions.html#sthash.3j3Egp26.dpuf