tag:blogger.com,1999:blog-53599537847577643792024-03-19T10:24:14.770+05:30Ajinkya Mandhare"The Goal is not to live forever...the goal is to create something that will"Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.comBlogger57125tag:blogger.com,1999:blog-5359953784757764379.post-70443415668802966982014-07-29T10:06:00.001+05:302014-07-29T10:06:32.045+05:30Zend Framework from Scratch Part II: MVC and Creating Zend Project<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8qPQ_GzaZDVOWNLGc0Bij4TUEWmhNpufL12m2NxIzwGfgkru2luvDgFB5F34ceqAzn6Fa9_CXcNnCk7MQ8LVpoFFwsoi_rA8-hanYlPdQkig5-rh-snXp8LFQQcaPFVkgRPEqiVeSeWY/s1600/Zend+Framework+from+Scratch.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8qPQ_GzaZDVOWNLGc0Bij4TUEWmhNpufL12m2NxIzwGfgkru2luvDgFB5F34ceqAzn6Fa9_CXcNnCk7MQ8LVpoFFwsoi_rA8-hanYlPdQkig5-rh-snXp8LFQQcaPFVkgRPEqiVeSeWY/s1600/Zend+Framework+from+Scratch.jpg" height="210" width="400" /></a></div>
In the Part I of the 'Zend from Scratch' series, we installed Zend and configured the environment to create our first Zend project. Continuing with our 'Zend from Scratch' series, we will have a look at the MVC framework using Zend and then create our first Zend web application. For those who haven't read the Part I of this series, here's the blog post of it:<br />
<div style="text-align: center;">
<b><a href="http://ajinkyamandhare.blogspot.in/2014/07/zend-from-scratch-part-i-install-and.html">Zend from Scratch Part I: Install and Configure PHP Zend Framework</a></b></div>
<div style="text-align: left;">
<br /></div>
<h3 style="text-align: left;">
Model-View-Controller (MVC) framework:</h3>
<div style="text-align: left;">
<b>Model–view–controller (MVC)</b> is a software architectural pattern for implementing user interfaces. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user.</div>
<div style="text-align: left;">
courtesy: <a href="http://framework.zend.com/manual/en/learning.quickstart.intro.html" sl-processed="1" style="background-color: #fefefe; border: none; box-sizing: border-box; color: #136fd2; font-family: 'Helvetica Neue', Arial, sans-serif; font-size: 13px; line-height: 26px; outline: none;" target="_blank">http://framework.zend.com</a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZt8GkVtdspB_EMLiaXfO-VOKqACE_u8UBsxknyE21yQtTQycTxi7YTvcNRYdgbNmTtyGAAswDh4RRR5S0LBfxo7w01BAzJNfZX_ErvQpNwsUBX0HpWmeO9RU90uR9CLN8vkCODjM5Us0/s1600/mvc.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZt8GkVtdspB_EMLiaXfO-VOKqACE_u8UBsxknyE21yQtTQycTxi7YTvcNRYdgbNmTtyGAAswDh4RRR5S0LBfxo7w01BAzJNfZX_ErvQpNwsUBX0HpWmeO9RU90uR9CLN8vkCODjM5Us0/s1600/mvc.png" height="278" width="400" /></a></div>
<div style="text-align: left;">
</div>
<ul style="text-align: left;">
<li><i>Model </i>- This is the part of your application that defines its basic functionality behind a set of abstractions. Data access routines and some business logic can be defined in the model.</li>
<li><i>View </i>- Views define exactly what is presented to the user. Usually controllers pass data to each view to render in some format. Views will often collect data from the user, as well. This is where you're likely to find HTML markup in your MVC applications.</li>
<li><i>Controller </i>- Controllers bind the whole pattern together. They manipulate models, decide which view to display based on the user's request and other factors, pass along the data that each view will need, or hand off control to another controller entirely.</li>
</ul>
<div>
<br /></div>
<div>
We will discuss more on MVC and how it fits in the Zend framework once we create our first project.</div>
<div>
<br /></div>
<h3 style="text-align: left;">
Create a Zend Framework Project:</h3>
<div>
Once you have completed all the steps in <a href="http://ajinkyamandhare.blogspot.in/2014/07/zend-from-scratch-part-i-install-and.html">Part I of this series</a>, we can start with creating of first PHP Zend project.</div>
<div>
Open command prompt and navigate to the folder where you want to create your project. It should be the folder where the server points to. If you have XAMPP installed, its 'C:\xampp\htdocs'. Now run the below command:</div>
<div style="text-align: center;">
<i><b>zf create project zendtest</b></i></div>
<div style="text-align: left;">
Here, 'zendtest' is the name of the project.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhjeShpl0t1IDQMyo4sjSOem4k9XwlSEHhQfEeFb7jlZp05qa8DRTt-UXr_9MdrGGB_evFlcU-ZpfvbGVIpoo-JtosiZ_PpAXuSmybP7j4C6OThmWOIhBtdiAwiOXAvwV3-YebaWBHYcE/s1600/zendcreate.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhjeShpl0t1IDQMyo4sjSOem4k9XwlSEHhQfEeFb7jlZp05qa8DRTt-UXr_9MdrGGB_evFlcU-ZpfvbGVIpoo-JtosiZ_PpAXuSmybP7j4C6OThmWOIhBtdiAwiOXAvwV3-YebaWBHYcE/s1600/zendcreate.PNG" height="321" width="640" /></a></div>
<div style="text-align: left;">
<br /></div>
<div>
You may get an error for 'PHPUnit_Framework_TestCase', but this should not be a concern as it will not create any hindrance while working with the development activities. The error is related to Unit Testing.</div>
<div>
<br /></div>
<div>
Once you run the above command, you can find a folder named 'zendtest' (the name of our project) in the 'htdocs' folder. Below is the directory structure of our newly created project:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjssOySMQXYhbw60S8NPcIdHgR5-3hC-LHBnAcpe2YX2q7nCHW6D-zsVDqD1B4r9ZGk8iZJkp5rdSb3ZnO8PzZ8guknHQnCpMFRaq4pAD5ciKTke1VLJXALDmix6ePmHo85jDXhxetRMp4/s1600/zendprojstructure.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjssOySMQXYhbw60S8NPcIdHgR5-3hC-LHBnAcpe2YX2q7nCHW6D-zsVDqD1B4r9ZGk8iZJkp5rdSb3ZnO8PzZ8guknHQnCpMFRaq4pAD5ciKTke1VLJXALDmix6ePmHo85jDXhxetRMp4/s1600/zendprojstructure.PNG" height="478" width="640" /></a></div>
<div>
<br /></div>
<div>
Now, once we can see the directory structure, we can relate this back to the MVC framework.</div>
<div>
<br /></div>
<h3 style="text-align: left;">
Zend Framework and MVC:</h3>
<div>
Open the 'application' folder in the newly created project:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglBgbune5oq6rxEolyxBbNQjujMbcrrq6JqYn9atjc_i-GxevIaYTL9eKrOQdkGgWEI5SoMJ4Alj1uMh0JlCUE_wJiKdIJWBGt8ELZa4iubgU1bG5ptsoGiKLwF0J2ASPsD_MMd_hmr84/s1600/zendmvc.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglBgbune5oq6rxEolyxBbNQjujMbcrrq6JqYn9atjc_i-GxevIaYTL9eKrOQdkGgWEI5SoMJ4Alj1uMh0JlCUE_wJiKdIJWBGt8ELZa4iubgU1bG5ptsoGiKLwF0J2ASPsD_MMd_hmr84/s1600/zendmvc.PNG" height="478" width="640" /></a></div>
<div>
<br /></div>
<div>
As you can see, there are three prominent folders: models, views and controllers.</div>
<div>
<br /></div>
<h3 style="text-align: left;">
Controllers:</h3>
<div>
Your application's action controllers contain your application workflow, and do the work of mapping your requests to the appropriate models and views.<br />
Open the IndexController.php file in the controllers folder:</div>
<div>
<br /></div>
</div>
<pre><?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
}
</pre>
Note the method 'indexAction()'. IndexController is a fallback controller and which also serves the home page of the site. Since there is nothing in the indexAction() method right now, it takes the default view, which is 'C:\xampp\htdocs\zendtest\application\views\scripts\index\index.phtml'. This is nothing but the home page of your project.<br />
Open your browser and goto<br />
<div style="text-align: center;">
http://localhost/zendtest/public</div>
<div style="text-align: left;">
This is what you get:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkupGnt9chXrdjxXQ4MhdXvzGwezre-JQThgW6HnLmyMgzQfk3Ec3984Ge4ifao2-kiXIf2raWR1bEZZqRQvUQ0KV8FA8ZXPD7kgaqfi5cYC_E8z9sk5QmRHhHWT7lBph2_N-1evDjo7U/s1600/homepage.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkupGnt9chXrdjxXQ4MhdXvzGwezre-JQThgW6HnLmyMgzQfk3Ec3984Ge4ifao2-kiXIf2raWR1bEZZqRQvUQ0KV8FA8ZXPD7kgaqfi5cYC_E8z9sk5QmRHhHWT7lBph2_N-1evDjo7U/s1600/homepage.PNG" height="267" width="400" /></a></div>
<div style="text-align: left;">
This page is nothing but the index.phtml in 'C:\xampp\htdocs\zendtest\application\views\scripts\index'.</div>
<div style="text-align: left;">
Now, lets have a look into Views.</div>
<div style="text-align: left;">
<br /></div>
<h3 style="text-align: left;">
Views:</h3>
<div>
View scripts are placed in application/views/scripts/, where they are further categorized using the controller names. In our case, we have an IndexController and an ErrorController, and thus we have corresponding index/ and error/ subdirectories within our view scripts directory.<br />
<br />
<h3 style="text-align: left;">
Creating a Layout:</h3>
You may have noticed that the view scripts in the previous sections were HTML fragments- not complete pages, and they lack html, head, and body tags. This is purposely done by design, so that all actions return content related to that action only, and not the whole application. This gives a consistent look and feel throughout the application.<br />
To create a layout, open the command prompt and navigate to the project directory. Now run the below command:<br />
<div style="text-align: center;">
<i>zf enable layout</i></div>
<div style="text-align: left;">
The output is as below:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh50qKH6M53V9XY_G8JLLZ_omcAwxponunw9nstR8NGBhUz7WHOZ5y3FlUglYTIJbC9oRVkL4RpEEkP2xPxY2DGkGcxGE2-wYvKejeRprwUw2NWiv4CwbkYkTih528kweufrTd5ncR_d7s/s1600/layout.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh50qKH6M53V9XY_G8JLLZ_omcAwxponunw9nstR8NGBhUz7WHOZ5y3FlUglYTIJbC9oRVkL4RpEEkP2xPxY2DGkGcxGE2-wYvKejeRprwUw2NWiv4CwbkYkTih528kweufrTd5ncR_d7s/s1600/layout.PNG" height="324" width="640" /></a></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
This will create a 'layout.phtml' file in 'C:\xampp\htdocs\zendtest\application\layouts\scripts'. If we open the file, below is what we see:</div>
<div style="text-align: left;">
<br /></div>
</div>
</div>
<pre><?php echo $this->layout()->content; ?>
</pre>
</div>
<br />
This is nothing but echoing the content from the view. We need to wrap this content with proper header and footer files. Replace the code in 'layout.phtml' file with the below code:<br />
<br /></div>
<pre><!DOCTYPE html>
<html>
<head>
<title>Zend Test</title>
</head>
<body>
<div id="wrap">
<div id="header">
<p>This is the header</p>
</div>
<div id="content">
<!-- Echo our content here! -->
<?php echo $this->layout()->content; ?>
</div>
<div id="footer">
<p>This is the footer</p>
</div>
</div>
</body>
</html>
</pre>
<br />
Now, again goto 'http://localhost/zendtest/public' in your browser. You now have the previous page with a proper header and footer!!<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHta-ggE8PPr4Qa_dJT2ALnfB4VySB5VwKhTXxkhbF0-YmV3CqQXoVTZnIwigKgnj_1Gruiz7qjvHffX8dsOYYERnUWk39jaOYgGhMeCEY8g1RDtVGRjLO6DNvDhBEFFK3p_BfJUQ290Y/s1600/layout1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHta-ggE8PPr4Qa_dJT2ALnfB4VySB5VwKhTXxkhbF0-YmV3CqQXoVTZnIwigKgnj_1Gruiz7qjvHffX8dsOYYERnUWk39jaOYgGhMeCEY8g1RDtVGRjLO6DNvDhBEFFK3p_BfJUQ290Y/s1600/layout1.PNG" height="596" width="640" /></a></div>
<br />
<br />
So far, we have created the basic layout of our site using the Zend framework. In the next part, we will cover creating Models and database, creating new controllers and the rest of the things required to create a full-fledged web site.<br />
<br />
A summary of what we covered in this tutorial:<br />
<br />
<ul style="text-align: left;">
<li>What is Model-View-Controller framework</li>
<li>Zend Framework as an MVC</li>
<li>Creating Zend Project</li>
<li>Understanding the Controllers and Views in Zend Framework</li>
<li>Creating a layout using Zend</li>
</ul>
<div>
Stay tuned for the final segment of this three part Zend from scratch series.</div>
<div>
You can subscribe for free or become a follower to get the latest alerts and posts.</div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com5tag:blogger.com,1999:blog-5359953784757764379.post-2383028890697508542014-07-27T10:57:00.000+05:302014-07-29T11:34:43.094+05:30Zend Framework from Scratch Part I: Install and Configure PHP Zend Framework<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwfBjflh3hxq9MhN5qMUSHoPiMf3L13e0ZdeYRndjAYkl7K247bu54C88okJRKeHaq03ZtwCIIwC1ywudcXiMiIOkR1gCEhY8myhgPkZGj3YB4MIZKznQ1nkMTLzK9Y9fn01XlKRY6UWg/s1600/Zend+Framework+from+Scratch.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwfBjflh3hxq9MhN5qMUSHoPiMf3L13e0ZdeYRndjAYkl7K247bu54C88okJRKeHaq03ZtwCIIwC1ywudcXiMiIOkR1gCEhY8myhgPkZGj3YB4MIZKznQ1nkMTLzK9Y9fn01XlKRY6UWg/s1600/Zend+Framework+from+Scratch.jpg" height="210" width="400" /></a></div>
<b>Zend Framework (ZF)</b> is an open source, object-oriented, full-stack PHP framework created by Zend Technologies implemented in PHP 5 and licensed under the New BSD License.<br />
<br />
In this 'Zend from Scratch' series, we will try to get the understanding about Zend Framework...not theoretically, but covering things like installing and configuring Zend Framework, understanding the MVC framework and developing a sample application using Zend.<br />
<br />
In this series, I would be using XAMPP for all purposes. XAMPP is nothing but a package of PHP, MySQL, Apache and other services. So, the PHP environment at my end is set up with XAMPP. You can download xampp from <a href="https://www.apachefriends.org/index.html">https://www.apachefriends.org/index.html</a>.<br />
<br />
So, lets get started...This part of the series will cover Installing and Configuring the Zend Framework on Windows.<br />
<br />
<h3 style="text-align: left;">
System Requirements:</h3>
<div>
Zend Framework version 1.7 requires PHP 5.2.4 or later. Previous versions required PHP 5.1.4 or later, although the ZF Programmer's Reference Guide strongly recommended PHP 5.2.3 or later for security and performance improvements included in these versions of PHP.</div>
<br />
<h3 style="text-align: left;">
<span style="color: #666666;">Step 1:</span> Download Zend Framework</h3>
<div>
Download the latest version of Zend Framework 1 (Full) from <a href="http://framework.zend.com/">http://framework.zend.com/</a>. At the time of writing this tutorial, the latest version of Zend was 1.12.7.</div>
<div>
<br /></div>
<div>
<h3>
<span style="color: #666666;">Step 2:</span> Configure Zend Framework</h3>
</div>
<div>
<ul style="text-align: left;">
<li>Once you download the .zip file, extract its contents to a folder. The folder structure after extracting should look like this:</li>
</ul>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8Bx2tc7MV8hx5PXNdanwNrcctiZ_jYu3lh5nuT_RbjQVOexPWRUmjvmWjARJcKrek0PxbC-u9tbvGiOs8TQJpFn_vOZV88pm9y5rhfdxyh_dM6_yR3Feq61NYpIgTxkhsSh5n9fdaAUc/s1600/step1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8Bx2tc7MV8hx5PXNdanwNrcctiZ_jYu3lh5nuT_RbjQVOexPWRUmjvmWjARJcKrek0PxbC-u9tbvGiOs8TQJpFn_vOZV88pm9y5rhfdxyh_dM6_yR3Feq61NYpIgTxkhsSh5n9fdaAUc/s1600/step1.JPG" height="520" width="640" /></a></div>
<div>
<ul style="text-align: left;">
<li>Now, copy the 'bin' folder and paste it in the 'PHP' folder, which for me (since I'm using xampp) is 'C:\xampp\php'. Rename the copied folder to 'zend-bin'.</li>
</ul>
</div>
<div>
<ul style="text-align: left;">
<li>Open the 'library' folder in the extracted folder. You can find a folder named 'Zend' in it. Copy this 'Zend' folder and paste it in your PHP's include_path. You can find the include_path for your environment in the 'php.ini' file. The default include_path for xampp is:</li>
</ul>
</div>
<div>
For UNIX:</div>
<div>
<div>
include_path = ".:/php/includes"</div>
<div>
<br /></div>
<div>
For Windows:</div>
<div>
include_path = ".;C:\xampp\php\PEAR"</div>
</div>
<div>
<br /></div>
<div>
The format of include_path is "path1;path2". The '.'(dot) in path1 means the current directory. So, there are basically 2 include_path(s).</div>
<div>
<ul style="text-align: left;">
<li>Lastly, we need to configure the Zend CLI tool. To do this, we need to add the 'zend-bin' folder to the path System variables. Right click on My Computer and select Properties. In the Advanced tab, click on 'Environment variables'. Here, in the 'System Variables' section, click on edit, and add the path to 'zend-bin' folder (C:\xampp\php\zend-bin) at the end:</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0oBrt2X1f1UY2LZ4ohWJJkfF5MS7Od8Ig0Pu5IgFS8THPRKCst4IkF91sX6kQG3mw3rqlybMGQYLZmk6pPvx0grutQZO8oG88cG5KZEjtA1bES3cOUyjS3OXjZZ28MvxWzbJVy8j3VpA/s1600/step+2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0oBrt2X1f1UY2LZ4ohWJJkfF5MS7Od8Ig0Pu5IgFS8THPRKCst4IkF91sX6kQG3mw3rqlybMGQYLZmk6pPvx0grutQZO8oG88cG5KZEjtA1bES3cOUyjS3OXjZZ28MvxWzbJVy8j3VpA/s1600/step+2.JPG" height="640" width="552" /></a></div>
<div>
<ul style="text-align: left;">
<li>Just to ensure that the setup is fine (which it should be if you have followed the steps exactly), open the command prompt and run 'zf --help'. This command gives a list of all the commands you can use with Zend CLI. You should get he below output:</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcuZ2NsBR-Nlt5qJqcwZTBG9u7M9VI5mNHgV4AmC8uo1tHZjL-vNH4Irncd_Rr3xgDrHr233Fduuwi7HTAzCKvXKeeHq8FveuJiVRm07CfQ5s9HYagkdzDIgnj5_tB63aa2xbkOVUHlfQ/s1600/zfhelp.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcuZ2NsBR-Nlt5qJqcwZTBG9u7M9VI5mNHgV4AmC8uo1tHZjL-vNH4Irncd_Rr3xgDrHr233Fduuwi7HTAzCKvXKeeHq8FveuJiVRm07CfQ5s9HYagkdzDIgnj5_tB63aa2xbkOVUHlfQ/s1600/zfhelp.JPG" height="321" width="640" /></a></div>
<div>
<br /></div>
</div>
</div>
<div>
And there you are!! You have just set up the environment for creating your first project using the Zend Framework.</div>
<div>
<br /></div>
<div>
The next part of this series will give a brief idea about the MVC architecture of the Zend framework, and we will create our first project using Zend...So stay tuned!!</div>
<div>
<br /></div>
<div>
You can subscribe for free or become a follower to get the latest alerts and posts.<br />
<br />
<h3 style="text-align: left;">
<a href="http://ajinkyamandhare.blogspot.in/2014/07/zend-framework-from-scratch-part-ii-mvc.html"><b>For the Part II of this series, click here.</b></a></h3>
</div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com1tag:blogger.com,1999:blog-5359953784757764379.post-10152836501994399712014-07-21T11:06:00.002+05:302014-07-21T11:49:57.227+05:30Print Web Page using JavaScript<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg9hiWVoHLirHg0r0dDnTBW1VfHLUUXTCe9sIZk6t-DmzMip_tbX8P03J7Dbr1mzUfrEOSGUwIG7-SlMXc7mh1Fq8zRJzGnlUEFitIJVuABxlEscWPo3RmU0rKGUIFX24DAArbR0ilWjo/s1600/unnamed.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg9hiWVoHLirHg0r0dDnTBW1VfHLUUXTCe9sIZk6t-DmzMip_tbX8P03J7Dbr1mzUfrEOSGUwIG7-SlMXc7mh1Fq8zRJzGnlUEFitIJVuABxlEscWPo3RmU0rKGUIFX24DAArbR0ilWjo/s1600/unnamed.png" height="200" width="200" /></a></div>
Many a times, we come across situations where we have to selectively print only a certain part of a web page. When it comes to a normal print command, it will print the entire web page for you. However, what if you want only a certain section, say a certain <div>...</div> to be printed, and exclude the content of the rest of the page?<br />
This tutorial aims at doing just the thing...<br />
<br />
Step 1: Enclose the content that you want to be printed in a <div> tag, and name it, say 'report':<br />
<br />
<pre><div id="report">
.
.
Your Content goes here...
.
.
</div>
</pre>
</div>
<br />
Step 2: Add a print button:<br />
<br />
<pre><input type="button" value="Print Summary" onclick="printContent('report')"/>
</pre>
</div>
<br />
As we see in the above snippet, 'printContent()' is the function that would do the printing job for us. To this function, we pass the id of the <div> tag whose content we want to print.<br />
<br />
Step 3: Create a javaScript function 'printContent()':<br />
At the bottom of the page, add the below javascript function<br />
<br />
<pre>
<script type="text/javascript">
<!--
function printContent(id){
str=document.getElementById(id).innerHTML
newwin=window.open('','printwin','left=100,top=100,width=400,height=400')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Summary</TITLE>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}
//-->
</script>
</pre>
</div>
<br />
The above function will take the id of the <div> tag whose content we want to print.<br />
And there you are!! You can now print the page. With the help of software like PDF Creator, now you can also selectively print the page to a PDF file.<br />
This functionality can be used where you want to print reports, receipts etc.</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com2tag:blogger.com,1999:blog-5359953784757764379.post-50426578199142103022014-07-17T00:49:00.000+05:302014-07-18T14:13:15.302+05:30Forgot Password Functionality in PHP<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5k9qWsj8ebAJuuNgLw7jOHfdUz8CnPZPJX3FPmDoIZPeGZu3CkFhZP_ZTxI5VytKTdCGzhBr_XpjlnouI_eCcmphMOnPrj7zfEDQtdXBdBrNOxRMp3meg8RZCZc8vSxZPATzJCIDBGSg/s1600/ForgotPwd.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5k9qWsj8ebAJuuNgLw7jOHfdUz8CnPZPJX3FPmDoIZPeGZu3CkFhZP_ZTxI5VytKTdCGzhBr_XpjlnouI_eCcmphMOnPrj7zfEDQtdXBdBrNOxRMp3meg8RZCZc8vSxZPATzJCIDBGSg/s1600/ForgotPwd.jpg" height="179" width="320" /></a></div>
<br />
When you implement a Login functionality, one thing that becomes an obvious inclusion is the 'Forgot Password' functionality. There are several ways to implement the forgot password functionality, some of which may be:<br />
<br />
<br />
<ul style="text-align: left;">
<li>Ask the security Question</li>
<li>Send a new password to the registered mail, etc etc</li>
</ul>
<div>
But the most popular one is</div>
<div>
<ul style="text-align: left;">
<li>Send an encoded, one time password reset link to the registered mail id</li>
</ul>
<div>
We would be discussing on this, i.e. the password reset link functionality implementation in this tutorial.</div>
</div>
<div>
<br /></div>
<div>
Before we get on with the actual coding, we need to create a proper database schema:</div>
<div>
In the Table where you store the login credentials, add another column 'forgotpassword', which will store the encoded random string that you would be sending to the registered mail id.</div>
<br />
Now comes the code...<br />
<br />
Step 1: Ask for the email id with which the user is registered<br />
<br /></div>
<div>
<pre class="brush:php"><?php
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
if(isset($_POST['submit'])) {
$selectuser="Select * from USERTABLE where emailid='".addslashes($_POST['email'])."'";
$result = mysql_query($selectuser);
$numrows = mysql_num_rows($result);
if($numrows == 1) {
$row = mysql_fetch_assoc($result);
$validusername=$result['username'];
for($i = 0; $i < 16; $i++) {
$randomstring .= chr(mt_rand(1,126));
}
$verifyurl = "resetpwd.php";
$verifystring = urlencode($randomstring);
$verifyemail = urlencode($_POST['email']);
$updateuser="Update USERTABLE SET forgotpassword='".addslashes($randomstring)."' WHERE emailid='".addslashes($_POST['email'])."'";
mysql_query($updateuser);
$mail_body=<<<_MAIL_
Hi,
A request has been made to reset the password for your account.
Please click on the following link to go to the password reset page:
$verifyurl?email=$verifyemail&verify=$verifystring
_MAIL_;
require("class.phpmailer.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = ""; //Add smtp details
$mailer->SMTPAuth = TRUE;
$mailer->Username = ""; // Change this to your gmail adress
$mailer->Password = ""; // Change this to your gmail password
$mailer->From = ""; // This HAVE TO be your gmail adress
$mailer->FromName = ""; // This is the from name in the email, you can put anything you like here
$mailer->Body = $mail_body;
$mailer->Subject = "User Verification";
$mailer->AddAddress($_POST['email']); // This is where you put the email adress of the person you want to mail
if(!$mailer->Send()){
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else{
echo "<center>A link has been
emailed to the address you entered below.
Please follow the link in the email to reset the passwod for
your account.</center><br>";
}
}
else{
echo "We could not find any registered user with the email id as ".addslashes($_POST['email'])."<br>
Please Enter the correct mail id & try again";
}
}
else{
?>
<div id="content">
<form action="forgotpwd.php" method="post">
<table>
<tr>
<td>Enter the Mail Id you registered with</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>
<?php
}
?>
</pre>
In the above snippet of code, We ask the user to enter the mail id he/she registered with. Once the user submits the form, you first check if the email id is present in the database, if not, you notify the user accordingly.<br />
Once you find the email id in the database, the next step is to create a random string, encode it and append it to the password reset page url. Encoding of a string can be done using urlencode() method in PHP.<br />
We also store the encoded randomly generated string to the database. Next, encode the mail id of the user and append it too to the url. The next part is where we send this url to the registered mail id. For this, I have used PHP Mailer.<br />
To know more about PHP Mailer as to how it works, refer to my tutorial on this: <a href="http://ajinkyamandhare.blogspot.in/2012/03/sending-email-using-php.html">Sending Email using PHP</a><br />
<br />
Step 2: Check the encoded url when the user clicks it from his mail<br />
<br /></div>
</div>
<pre><?php
$verify = addslashes(urldecode($_GET['verify']));
$verifymail = urldecode($_GET['email']);
if (isset($_POST['confirmpwdreset'])) {
$resetpwd="Update USERTABLE SET password='". md5($_POST['newpwd'])."' WHERE emailid='".$verifymail."'";
if(mysql_query($resetpwd))
{
$removeverifystring="Update USERTABLE SET forgotpwd='' WHERE emailid='".$verifymail."'";
mysql_query($removeverifystring);
}
echo "<b>Your Password has been reset successfully.Login with your new password</b>";
}
else{
if($verify!=''){
$sql = "SELECT * FROM USERTABLE WHERE forgotpwd= '" . $verify . "' AND emailid = '" .$verifymail . "';";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
if($numrows == 1) {
$row = mysql_fetch_assoc($result);
echo "<br><h3>Hi </h3><br>";
echo "You can now reset your password<br><br>";
?>
<form name="reset" action="resetpwd.php?emailid=<?php echo $_GET['emailid'];?>&verify=<?php echo $_GET['verify'];?>" method="post">
<table>
<tr>
<td>New password: </td><td><input type="password" name="newpwd"></td>
</tr>
<tr>
<td>Confirm password: </td><td><input type="password" name="confirmpwd"></td>
</tr>
<tr>
<td></td><td><input type="submit" name="confirmpwdreset" value="Confirm"></td>
</tr>
</table>
<?php
}
else {
echo "The link is either invalid or has expired";
}
}
else echo "The link is either invalid or has expired";
}
?>
</pre>
<br />
<br />
Once the user clicks the url in the mail, we decode the random string and the email-id in the url. For decoding, we can use the urldecode() method in PHP. Next, all we have to do is to check the database for the combination of the random string and the mail-id. Once we find that combo, we ask the user to enter the new password, which on submission is updated in the database. As we update the database with the new password value, we reset the value of the corresponding 'forgotpassword' field to '' so that the same random string cannot be reused, thus ensuring one time usability of password reset url<br />
<br />
Thats it!! We now have a full fledged 'Forgot Password' functionality to make life easy for the users.<br />
<br /></div>Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com4tag:blogger.com,1999:blog-5359953784757764379.post-47949433425170064592014-06-14T13:58:00.000+05:302014-06-14T14:05:59.892+05:30Java code to remove redundant data / duplicate entries spread across multiple Files<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghzUHfvd-ufTCtTTGn-hSuyoAqZnFfC3hlnhYu9srJnGRgVFHCW-WEimL5aC2nT7gQgNKkvhKTBvgq9GhRuAUCMyY2U5Ukesa4UzW_rh0LUc50omtSDJj_nP8Vm5eCUDxDoIqx-kvAu9M/s1600/java-code.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghzUHfvd-ufTCtTTGn-hSuyoAqZnFfC3hlnhYu9srJnGRgVFHCW-WEimL5aC2nT7gQgNKkvhKTBvgq9GhRuAUCMyY2U5Ukesa4UzW_rh0LUc50omtSDJj_nP8Vm5eCUDxDoIqx-kvAu9M/s1600/java-code.jpg" height="265" width="400" /></a></div>
The scenario here was that there are several text files, with redundant data in them. The objective was to remove the redundant data spread across multiple text files, and collate the entire data in a single file. This task can ofcourse be done using excel macros, but not being too fond of excel, I preferred writing a java code for the same.<br />
Below is the Java code to accomplish this task:<br />
<br />
<br /></div>
<pre>package aj;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Load {
public static void main(String[] args) throws IOException {
System.out.println("Enter the no of files");
Scanner scr=new Scanner(System.in);
int no=scr.nextInt();
int i=1;
String source;
String dest = "Filepath\\Dest.txt";
String result = "Filepath\\Result.txt";
while(i<=no)
{
source = "Filepath\\File"+i+".txt";
copyContent(source, dest);
++i;
}
removeDuplicates(dest, result);
}
static void copyContent(String source, String dest)throws IOException {
File fin = new File(source);
FileInputStream fis = new FileInputStream(fin);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
FileWriter fstream = new FileWriter(dest, true);
BufferedWriter out = new BufferedWriter(fstream);
String aLine = null;
while ((aLine = in.readLine()) != null) {
out.write(aLine);
out.newLine();
}
out.newLine();
out.newLine();
out.write("***************************************************");
out.newLine();
out.newLine();
in.close();
out.close();
}
static void removeDuplicates(String dest, String result) throws IOException{
int flag=0;
File fin = new File(dest);
FileInputStream fis = new FileInputStream(fin);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
FileWriter fstream = new FileWriter(result, true);
BufferedWriter out = new BufferedWriter(fstream);
String aLine = null;
String bLine = null;
int i=1,j=1;
while ((aLine = in.readLine()) != null) {
j=i;
flag=0;
File fin1 = new File(dest);
FileInputStream fis1 = new FileInputStream(fin1);
BufferedReader in1;
in1 = new BufferedReader(new InputStreamReader(fis1));
if(aLine.equals("***************************************************")==true || i==1)
{
out.write(aLine);
out.newLine();
}
else{
while(j>1)
{
bLine = in1.readLine();
if (bLine!=null && bLine.equals(aLine)) {
flag=1;
}
--j;
}
if(flag==0)
{
out.write(aLine);
out.newLine();
}
}
++i;
in1.close();
}
in.close();
out.close();
}
}
</pre>
</div>
<br />
<br />
The function copyContent() copies the data from all the files to a single text file.<br />
Once this is done, the function removeDuplicates() removes the redundant data from the newly created file. The final cleaned data is now available in the 'Result.txt' file.</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com0tag:blogger.com,1999:blog-5359953784757764379.post-26997815282275954892014-04-28T23:40:00.001+05:302014-06-14T13:53:30.037+05:30Android Tutorial - First Android App: Flashlight<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVqiYKjUZFRzyTXk0qdl3aVzvXB-04Xc9Nn4Cw7MvmUEGNdbDm8Z_LdVMKIKOm8ZOTTu2tEUelWOX6uIITYyuIBgYBAFAn1BDrlV8uBXdzr3lkWRee_Q9-3t_NI5nhh0AuE6yi_fX17x4/s1600/Screenshot_2014-04-28-11-25-01.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVqiYKjUZFRzyTXk0qdl3aVzvXB-04Xc9Nn4Cw7MvmUEGNdbDm8Z_LdVMKIKOm8ZOTTu2tEUelWOX6uIITYyuIBgYBAFAn1BDrlV8uBXdzr3lkWRee_Q9-3t_NI5nhh0AuE6yi_fX17x4/s1600/Screenshot_2014-04-28-11-25-01.png" height="320" width="192" /></a></div>
Ever thought of creating your own mobile application? Well, with Android, creating your own app is no longer a tedious task, something that could be done only by the professionals. All you need is the basic knowledge of java and xml, and the right way to start off.<br />
This tutorial aims at creating a very basic android application, a flashlight.<br />
<br />
Pre-requisites:<br />
<br />
1. If using PC:<br />
<div>
<ul style="text-align: left;">
<li>Android SDK</li>
<li>Eclipse with ADT plugin</li>
</ul>
<div>
2. If using an Android device : Tablet, cell phone (I had built it on a tablet)</div>
</div>
<div>
<ul style="text-align: left;">
<li>An Android IDE, for which I used <a href="https://play.google.com/store/apps/details?id=com.aide.ui">AIDE</a></li>
</ul>
</div>
Now, lets get started with the tutorial:<br />
<br />
Step I: Create a new Android Project in Eclipse. I have named it 'Lumos', something you can expect from a Harry Potter fan :P<br />
<br />
Step II: Ask for Permissions<br />
In the AndroidManifest.xml file, you have to specify the permissions that your application would be requiring in order to perform its tasks. In our case, we require the access to the Camera and its functions in order to start the flashlight.<br />
Open the <b>AndroidManifest.xml</b> and change it to the one as below:<br />
<br />
<pre><?xml version="1.0" encoding="utf-8"?><br />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aj.flash"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name="com.aj.lumos.MainActivity"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:screenOrientation="portrait">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
</pre>
As you can see, the below two lines are the ones that are used to get the permission to access the camera and its functions:<br />
<br />
<pre><action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /></pre>
<br /></div>
</div>
Step III: The Layout of the App<br />
Eclipse by default creates a file named <b>main.xml</b> in res->Layout. Open the file and paste the following code:<br />
<br />
<pre><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/radial_background"
tools:context=".MainActivity" >
<ImageButton
android:id="@+id/btnSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dip"
android:src="@drawable/btn_switch_on"
android:background="@null"
android:contentDescription="@null"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:onClick="switchClicked"/>
<TextView android:text="Developed by aj"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:layout_width="fill_parent"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:layout_height="wrap_content"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:layout_alignParentBottom="true"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:layout_centerHorizontal="true"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:gravity="center"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:padding="15dip"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:textSize="13dip"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:textColor="#3b3b3b"
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:layout_marginBottom="15dip"/>
</RelativeLayout>
</pre>
</div>
<br />
The 'ImageButton' is nothing but the image of the bulb, which will be used as a button to switch the flashlight on and off. This button is identified by the id: 'btnSwitch'<br />
The 'TextView' field is the one where you can flaunt your name, telling the world that you are the developer of this app :P<br />
<br />
Step IV: The actual code<br />
Open the file MainActivity.java and paste the below code:<br />
<br />
<pre>package com.aj.lumos;
import com.aj.flash.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends Activity{
<span class="Apple-tab-span" style="white-space: pre;"> </span>ImageButton btnSwitch;
<span class="Apple-tab-span"> </span>private Camera camera;
<span class="Apple-tab-span" style="white-space: pre;"> </span>private boolean isFlashOn;
<span class="Apple-tab-span" style="white-space: pre;"> </span>private boolean hasFlash;
<span class="Apple-tab-span" style="white-space: pre;"> </span>Parameters params;
@SuppressWarnings("deprecation")
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
<span class="Apple-tab-span"> </span>btnSwitch = (ImageButton) findViewById(R.id.btnSwitch);
<span class="Apple-tab-span" style="white-space: pre;"> </span>hasFlash = getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
<span class="Apple-tab-span">
</span>
<span class="Apple-tab-span"> </span>if (!hasFlash) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
<span class="Apple-tab-span" style="white-space: pre;"> </span>alert.setTitle("Error");
<span class="Apple-tab-span" style="white-space: pre;"> </span>alert.setMessage("Sorry, your device doesn't support flash light!");
<span class="Apple-tab-span" style="white-space: pre;"> </span>alert.setButton("OK", new DialogInterface.OnClickListener() {
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void onClick(DialogInterface dialog, int which) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>finish();
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span"> </span>});
<span class="Apple-tab-span" style="white-space: pre;"> </span>alert.show();
<span class="Apple-tab-span" style="white-space: pre;"> </span>return;
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>getCamera();
<span class="Apple-tab-span"> </span>toggleswitch();
<span class="Apple-tab-span"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void switchClicked(View v){
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (isFlashOn) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>turnOffFlash();
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else {
<span class="Apple-tab-span" style="white-space: pre;"> </span>turnOnFlash();
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>private void getCamera() {
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (camera == null) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {
<span class="Apple-tab-span" style="white-space: pre;"> </span>camera = Camera.open();
<span class="Apple-tab-span" style="white-space: pre;"> </span>params = camera.getParameters();
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (RuntimeException e) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("Camera Error. Failed to Open. Error: ", e.getMessage());
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
//Turning On flash
<span class="Apple-tab-span" style="white-space: pre;"> </span>private void turnOnFlash() {
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (!isFlashOn) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (camera == null || params == null) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>return;
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;">
</span><span class="Apple-tab-span" style="white-space: pre;"> </span>params = camera.getParameters();
<span class="Apple-tab-span" style="white-space: pre;"> </span>params.setFlashMode(Parameters.FLASH_MODE_TORCH);
<span class="Apple-tab-span" style="white-space: pre;"> </span>camera.setParameters(params);
<span class="Apple-tab-span" style="white-space: pre;"> </span>camera.startPreview();
<span class="Apple-tab-span" style="white-space: pre;"> </span>isFlashOn = true;
<span class="Apple-tab-span" style="white-space: pre;"> </span>toggleswitch();
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
//Turning Off flash
<span class="Apple-tab-span" style="white-space: pre;"> </span>private void turnOffFlash() {
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (isFlashOn) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (camera == null || params == null) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>return;
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>params = camera.getParameters();
<span class="Apple-tab-span" style="white-space: pre;"> </span>params.setFlashMode(Parameters.FLASH_MODE_OFF);
<span class="Apple-tab-span" style="white-space: pre;"> </span>camera.setParameters(params);
<span class="Apple-tab-span" style="white-space: pre;"> </span>camera.stopPreview();
<span class="Apple-tab-span" style="white-space: pre;"> </span>isFlashOn = false;
<span class="Apple-tab-span"> </span>toggleswitch();
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>private void toggleswitch(){
<span class="Apple-tab-span" style="white-space: pre;"> </span>if(isFlashOn){
<span class="Apple-tab-span" style="white-space: pre;"> </span>btnSwitch.setImageResource(R.drawable.btn_switch_on);
<span class="Apple-tab-span" style="white-space: pre;"> </span>}else{
<span class="Apple-tab-span" style="white-space: pre;"> </span>btnSwitch.setImageResource(R.drawable.btn_switch_off);
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onStop() {
<span class="Apple-tab-span" style="white-space: pre;"> </span>super.onStop();
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (camera != null) {
<span class="Apple-tab-span" style="white-space: pre;"> </span>camera.release();
<span class="Apple-tab-span" style="white-space: pre;"> </span>camera = null;
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onDestroy() {
<span class="Apple-tab-span" style="white-space: pre;"> </span>super.onDestroy();
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onStart() {
<span class="Apple-tab-span" style="white-space: pre;"> </span>super.onStart();
<span class="Apple-tab-span" style="white-space: pre;"> </span>getCamera();
<span class="Apple-tab-span" style="white-space: pre;"> </span>}
<span class="Apple-tab-span" style="white-space: pre;"> </span>@Override
<span class="Apple-tab-span" style="white-space: pre;"> </span>protected void onPause() {
<span class="Apple-tab-span" style="white-space: pre;"> </span>super.onPause();
<span class="Apple-tab-span"> </span>}
}
</pre>
<div>
I have tried to modularize the above piece of code by defining separate methods for various tasks. The methods in the above snippet are self explanatory.<br />
<br />
You will be requiring a few images that have been used in this tutorial. Download these resources from the download box alongside or use this link: <a href="https://www.box.net/shared/pog97q9nq2ugxwbqeh7h">Resources</a><br />
These images and the xml file in the above zip go into res->drawable-hdpi<br />
<br />
Compile the above code and run it on your Android device.<br />
Voila!! We now have our own flashlight app!<br />
<br />
I have created an APK of the flashlight app, which can be downloaded from <a href="https://www.box.net/shared/zbw3tk8fdo7bhe765q7g">Lumos</a> or from the download box alongside.<br />
<br />
Have queries?? Stuck anywhere?? Post all the issues on <a href="http://www.compild.com/">Compild</a><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.compild.com/"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_hJtcHfaHGJhZgflqT_Ibh_DaVpLfXio0ZU91gZl1fNYtS5BPjQqaSnFYV2T7ae4wfVXsGi7VXBofY5WMkMq0RRl7f1GiguMfg-Z2SSm8OmbQh_h_75LN40osxCd0BQzMWrSd1LXkoaA/s1600/h.jpg" /></a></div>
<br /></div>
</div>Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com2tag:blogger.com,1999:blog-5359953784757764379.post-72591488497594747502013-12-23T10:07:00.000+05:302013-12-23T10:07:02.476+05:30Android Bootloop problem Fixed: The 'Jugaad' way<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinvWsdGHnrKda5EGQa4MHyAbL2D1afMX8IOH8uxwmnf1_xssWnTWDKNCVbYWjNxtlFSE17wVh-KOXlPu_ZRXL1VsyX6zAcjNmOJW2RBNXrpVwgYi5-E1-ozOlQ43mB-j3HxnClB0ZMhbU/s1600/bootloop.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinvWsdGHnrKda5EGQa4MHyAbL2D1afMX8IOH8uxwmnf1_xssWnTWDKNCVbYWjNxtlFSE17wVh-KOXlPu_ZRXL1VsyX6zAcjNmOJW2RBNXrpVwgYi5-E1-ozOlQ43mB-j3HxnClB0ZMhbU/s200/bootloop.jpg" width="200" /></a></div>
Having an Android phone arouses that natural inquisitiveness to play around with its firmware, to root the phone, install custom ROMs and do all sorts of crazy things with it. However, sometimes, you might end up messing up your beloved phone, and then start cursing yourself for all the foolishness you did. I was in a similar situation recently. With the craze for Kitkat spreading like a wild fire, I decided to install the latest Android 4.4 on my Samsung Galaxy S2. Be rest assured....this one time Samsung flagship device still holds strong when it comes to installing the latest firmwares. So, on the quest for Kitkat, I downloaded the CM 11 for GT-i9100, and with my phone already rooted, I took the Nandroid backup using the clockworkMod recovery. All set for yet another experiment on my phone (and btw...it has never disappointed me when it comes to flashing custom roms) I flashed the CM 11...but...got an error (Status 7), and the flashing failed. Determined to get Kitkat by hook or by crook, I did a factory reset of my phone...having at the back of my mind that I still have the complete system backup. Then I flashed the stock jelly bean ROM, just to make sure that the current custom rom on my phone is not causing a problem while flashing a new rom. Again, I tried with Kitkat, but it still gave the same error!! Now, why did the error occur is altogether a different mystery, which I'm yet to figure out. The problem started, when I tried restoring my backup...the phone got stuck in Boot loop...one of the worst nightmares for android users!!<br />
<br />
Now, generally, the boot loop problem gets fixed by removing the battery for some time and restarting the phone, or by wiping the cache and Dalvik cache repeatedly. However, it seemed that it wasn't my day, and everything I tried failed to boot my phone. And then I started doing something that almost everyone does at such situations...cursing myself...and more because I had done a factory reset of my phone. So, even though I knew that I can get back my phone by flashing the stock firmware, there was no chance, that I could get back my apps and data, which meant...the painful process of reinstalling everything from scratch. And what about all my messages...and all those levels I had completed in NFS, and what about my highest score in Temple Run...how am I gonna get all those things back??!! I tried googling a lot, but every forum said just one thing...flash the stock rom in case of boot loop problem, but damn!!...you wont get back your data.<br />
<br />
And then suddenly, a thought occurred...a way around...a 'Jugaad' that we are so good at!! I had the nandroid backup with me...which meant I had the backup of my apps and data in it. The problem was with booting the phone right? There was still a chance that the apps and data had been restored from the backup. So, firstly, I did a factory reset of my phone...just to wipe out everything that was in there. Then, I restored the nandroid backup (as expected, the phone got stuck in boot loop again). And then came the master stroke...I flashed it with the stock firmware I had with me. And then came the prayers....God...please give me my phone back....please...please!!<br />
<br />
It went past the Samsung logo...my heart racing like hell now....'Upgrading Android'....'Initializing the apps'....and Bingo!! Everything was in place...all my apps, all my contacts, messages...everything!! The only problem now was that my phone was not rooted as it was earlier, and it was again filled with all sorts of scrap inbuilt apps from Samsung, which I had previously removed. But that was welcome, as it was just a matter of few minutes and I could root my phone and purge it of those silly apps. The great thing was, that I got back my phone...and I had started loving it all the more now!!<br />
<br />
So, for all those who had given up after the boot loop problem....there is always a way....that's the beauty of Android! The only thing that you should have at your disposal is a backup of your phone.<br />
<br />
So, here's the jugaad in two simple steps:<br />
Step 1. Restore the nandroid backup(This is where the boot loop problem started for me)<br />
Step 2. Flash the stock firmware over the nandroid backup<br />
<br />
You'll have your phone 'almost' as it was earlier, with all your apps and data.<br />
<br />
<b>Have Queries?? Post it on our Discussion Forum <a href="http://www.compild.com/">Compild</a></b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg77Yo6p_mOo1VAMEX5SRamNHOQ0HvG0d-CGWJNY0yOZoAQEiGDeBIc0AmnhXCVvs6RC1rXhZfCM2zy8nDvDdwtCLEzX9JwVJbADu58iO0YS_LVv9z-ukqw0b7Y9gJ270PMcr2nf41CpDc/s1600/h.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="96" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg77Yo6p_mOo1VAMEX5SRamNHOQ0HvG0d-CGWJNY0yOZoAQEiGDeBIc0AmnhXCVvs6RC1rXhZfCM2zy8nDvDdwtCLEzX9JwVJbADu58iO0YS_LVv9z-ukqw0b7Y9gJ270PMcr2nf41CpDc/s640/h.jpg" width="640" /></a></div>
<span id="goog_850455399"></span><span id="goog_850455400"></span><br /></div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com0tag:blogger.com,1999:blog-5359953784757764379.post-46925454129915682022013-09-09T21:55:00.000+05:302013-11-29T08:27:57.616+05:30Read an Excel file using PHP<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXxInp5ZUGjTbaXyF25-jW8_EWYZetlJtiMek0yLRw-zIQKdniJO7mW-qlijrJaXZAhOgftiwOdKCJL_CcqrOMxv7QriEodc2myZD4IkGDpvkULW5kGq6aTwCFoU-mesU47nsKw3ZIxoA/s1600/PHP-Excel.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXxInp5ZUGjTbaXyF25-jW8_EWYZetlJtiMek0yLRw-zIQKdniJO7mW-qlijrJaXZAhOgftiwOdKCJL_CcqrOMxv7QriEodc2myZD4IkGDpvkULW5kGq6aTwCFoU-mesU47nsKw3ZIxoA/s1600/PHP-Excel.jpg" /></a></div>
Reading an excel file using some server-side scripting language is something that should be in the ammo of any developer. Now, Excel is something which I have always stayed away from...blame it on the insipid UI, or lack of various other features which databases like Oracle, MySql etc provide. However, one cannot deny the fact that Excel is rampantly used to maintain records, and at some point or other, you may have to use excel as an input to your code.<br />
<br />
I had faced such a situation recently, and after some googling, I managed to find a way to read the excel sheet and insert the corresponding entries to a MySql database. So, this post of mine will help you in reading an excel sheet using PHP. Once it is read and you have the values of the entries with you, its up to you as to what you like to do with it. In my case, I simply inserted those values in a MySql database.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.compild.com/"><img alt="Have queries?? Get them resolved..." border="0" height="97" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjGPYtMaxUfCU9Hz4HjlyQNV53rWNJ5gS0geZ8gbdMdq8JJSmT_9SLlVagrA_pVEy0rpxq_eY7INMoT04rc4Kj31ktM0hfZ_wka2wN_q1M_9JGY3fBTQLPvd5d3qP9E9RGH6M3D8LgUX4/s640/h.jpg" title="Have queries?? Get them resolved..." width="640" /></a></div>
<br />
What you need to get started:<br />
<a href="http://sourceforge.net/projects/phpexcelreader/">PHPExcelReader</a><br />
<a href="http://pear.php.net/package/Spreadsheet_Excel_Writer">SpreadsheetExcelWriter</a><br />
<br />
Download the above two packages. Extract both the packages. Now, in the PHPExcelReader package, find the <b>oleread.inc. </b>Copy this file, and paste it to <b>Spreadsheet\Excel\Reader</b> folder in the SpreadsheetExcelWriter package. It does not have the Reader folder by default. Create that folder and paste the oleread.inc file in it. Now, save the oleread.inc file in the same folder as <b>OLERead.php</b>.<br />
Now, copy the entire <b>Spreadsheet</b> folder from <b>SpreadsheetExcelWriter</b> package, and paste it in the <b>Excel</b> folder in <b>PHPExcelReader</b> package. This 'Excel' folder in the PHPExcelReader package is what we will be using for reading from an excel file using PHP. Once you have done all this copying and pasting, you are all set to read an Excel sheet!!<br />
<br />
Step I: Create a simple HTML file 'importexcel.html' to take the excel sheet as an input:</div>
<div>
<pre class="brush:html"><form action="import.php" enctype="multipart/form-data" method="post">
File Name: <input type="file" name="file" id="file">
<input type="submit" name="Submit" value="Submit" />
</form>
</pre>
</div>
</div>
<br />
Step II: Create a PHP file 'import.php', where we write the action part for the above form:<br />
<br />
<pre class="brush:php"><?php
mysql_connect(hostname,username, password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db(dbname);
include 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read($_FILES["file"]["tmp_name"]);
//columns:
$sql = "INSERT INTO `TABLENAME` (";
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
{
$sql .= "`" . mysql_escape_string($data->sheets[0]['cells'][1][$j]) . "`,";
}
$sql = substr($sql, 0, -1) . ") VALUES\r\n";
//cells
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++)
{
$sql .= "(";
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)
{
$sql .= "" . mysql_escape_string($data->sheets[0]['cells'][$i][$j]) . ",";
}
$sql = substr($sql, 0, -1) . "),\r\n";
}
$sql = substr($sql, 0, -3) . ";";
echo $sql;
mysql_query($sql);
?>
</pre>
</div>
</div>
<br />
<br />
Make sure that you have the <b>'Excel' </b>folder in the root directory.<br />
<br />
If you look at the output of the code, it will print the INSERT query, which is then used in mysql_query to execute the query.<br />
<br />
Whats a take away from this tutorial is that, you can access the entries from the Excel sheet by creating an object ('$data' in our example) of <b>Spreadsheet_Excel_Reader</b> class, and then use this object as $data->sheets[<sheet number>]['cells'][<row number>][<column number>] to access the (row,column)th entry of the corresponding sheet number in the excel.<br />
Once you can access these entries, you can use them in whichever way you want....creating a table in html, or inserting those entries in a database, or any other processing.<br />
<br />
Thats it!! Simple it was, wasn't it? Now, go ahead...use this code to read an Excel sheet....njoy!!<br />
<br />
<b>Have Queries?? Post it on our Discussion Forum <a href="http://www.compild.com/">Compild</a></b></div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com10tag:blogger.com,1999:blog-5359953784757764379.post-5654659802156246712013-04-29T18:28:00.000+05:302013-11-29T08:31:57.931+05:30Root Samsung Galaxy S2 GT-i9100 Jelly Bean and install Clockwork Recovery Mod<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjhsI0nyIy8nnznaC00IiH_xeFKZO-1skCmxTlSaojhhiil3l7Rx1Hucq2GgqeRRX-pKFVeNOUEvo7DG2I60LK_3C6aymbr7KEW7SahBl_jsJn2k7E8M2dFHo9N5ZC2fDASIh-kNNPT6Y/s1600/galaxys2jellybean.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjhsI0nyIy8nnznaC00IiH_xeFKZO-1skCmxTlSaojhhiil3l7Rx1Hucq2GgqeRRX-pKFVeNOUEvo7DG2I60LK_3C6aymbr7KEW7SahBl_jsJn2k7E8M2dFHo9N5ZC2fDASIh-kNNPT6Y/s400/galaxys2jellybean.jpg" width="400" /></a></div>
With the official Jelly Bean update now available for Galaxy SII, one thing that any android fan would be looking for would be 'How to Root it?'. Rooting the phone unleashes the true power it withholds, making the Android experience all the more exiting! Also, once you root your phone, one very basic thing you need is the Clockwork Recovery Mod.<br />
The below tutorial gives the detailed steps for doing just the same.<br />
The advantage of this method is that, as in the normal rooting, there is no yellow triangle that appears on your booting screen.<br />
<br />
Make sure you have following things in place:<br />
<ul style="text-align: left;">
<li>This guide is for Samsung Galaxy SII GT-i9100 (international version) only. I have not tried this out on any other version</li>
<li>Take a backup of whatever you can...ie contacts, messages etc. You may not be able to take a system backup, as this requires rooted phone</li>
<li>Ensure that the phone has atleast 85% battery charge</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.compild.com/"><img alt="Have queries?? Get them resolved..." border="0" height="96" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNOjFNPqxn3tsmiA3DUdxLP9c3_Ur1gz-SHoISOxxxORefDGP2thMO0-S1rbTXwWjDK_t9pkav5kN8ymd8MdPMQRaQUtOmFyuVWRDQejku1sdv9-pyaABWkbl3scAz3MU5AKQ4oTT3Xms/s640/h.jpg" title="Have queries?? Get them resolved..." width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
If you have the above things set, then you are ready for what follows...<br />
<br />
But first thing first:<br />
<b><span style="color: #444444;">Disclaimer</span></b>: The instructions provided in this guide are meant for reference purpose only. I will not be held liable if the device is damaged during the installation. Users must proceed at their own risk.<br />
<br />
This thing hardly takes about 5-10 minutes:<br />
<br />
<b><span style="color: #073763;">Files needed:</span></b><br />
1. SU-BB-Installer.zip(download it from the download box alongside)<br />
2. <a href="http://download2.clockworkmod.com/recoveries/recovery-clockwork-4.0.1.5-galaxys2.zip">Clockwork Recovery Mod</a><br />
<br />
<b><span style="color: #073763;">And here are the steps:</span></b><br />
<ol style="text-align: left;">
<li>Place both the files in SD card and boot the phone in recovery mode. To do this, power off your phone & then long press the Volume down + Power + Home buttons simultaneously</li>
<li>You would now be in the stock recovery mode. Now select 'Apply Update from External Storage' and then navigate to the 'SU-BB-Installer.zip' file, and select it using the Power button. Select Yes in the next step...This would now root your phone</li>
<li>Once done, again navigate back to the home screen of the stock recovery, and select 'Apply Update from External Storage'....this time, select the Clockwork Recovery Mod file</li>
<li>This would now replace your stock recovery by the Clockwork Recovery Mod</li>
<li>You can now play around with the various options available in the CWM, like taking a Nandroid backup</li>
<li>Now, reboot your phone</li>
<li>In the list of your applications, you would now see a 'Super User' App. If you are able to see this app...congrats!!... your phone is successfully rooted!</li>
</ol>
<div>
You can now install various apps like the Titanium backup, and other such apps, to tweak the performance of your phone. Once rooted, you also have the luxury to install a number of cool custom firmwares, which would have otherwise required a rooted phone...njoy:)<br />
<br />
Now, if you wish to unroot your phone, all you need to do is flash the official Jelly Bean Rom using Odin, and there would be no traces, to prove that your phone was ever rooted!!<br />
<br />
<b>Have queries?? Get them resolved on our Discussion Forum <a href="http://www.compild.com/">Compild</a></b></div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com5tag:blogger.com,1999:blog-5359953784757764379.post-72344148000192246802013-03-08T10:05:00.001+05:302013-11-29T08:37:21.839+05:30Multi Window and Ripple Lock Screen for Samsung Galaxy S2 GT-i9100 Jelly Bean(4.1.2)<div dir="ltr" style="text-align: left;" trbidi="on">
Samsung recently rolled out the JellyBean 4.1.2 update for Galaxy S2. The S2 users, including myself were eagerly awaiting this upgrade, and the cellphone giant Samsung did not disappoint. The JB for S2 breathes in a new life in the phone with the new Nature UX interface, Google Now, and many other exciting things added to the already feature filled Samsung flagship device Galaxy S2.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.compild.com/"><img alt="Have queries?? Get them resolved..." border="0" height="96" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNOjFNPqxn3tsmiA3DUdxLP9c3_Ur1gz-SHoISOxxxORefDGP2thMO0-S1rbTXwWjDK_t9pkav5kN8ymd8MdPMQRaQUtOmFyuVWRDQejku1sdv9-pyaABWkbl3scAz3MU5AKQ4oTT3Xms/s640/h.jpg" title="Have queries?? Get them resolved..." width="640" /></a></div>
<br />
<br />
All said and done, there was still a major update that the S2 users were looking forward to....the much famed '<b>Multi-Window</b>' feature, as in Galaxy S3 and Note2. This was not included in the JB update for S2, which for me was a let down!!<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkBloTJ41RHtbxEFRwqNYpTtVR3GEbpQl_ww-yr9nX6m70IqzA6UvsR6pIosCGAkYoIIUaIBlL4nZoJdbxlTMvzGoneo7NTvaSZ5OMu5uI5I-IVb_0LBYwHSBLzR0518ynUf4FH3Y4G4s/s1600/Screenshot_2013-03-09-10-53-46.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkBloTJ41RHtbxEFRwqNYpTtVR3GEbpQl_ww-yr9nX6m70IqzA6UvsR6pIosCGAkYoIIUaIBlL4nZoJdbxlTMvzGoneo7NTvaSZ5OMu5uI5I-IVb_0LBYwHSBLzR0518ynUf4FH3Y4G4s/s320/Screenshot_2013-03-09-10-53-46.png" width="192" /></a></div>
I tried to search for methods to get multi window for my phone....did so much things in that process that at one time, my phone refused to boot back!!<br />
But then I found out these two methods....<br />
<br />
<ul style="text-align: left;">
<li>'Installing Mods for the Stock JB firmware'(This method is for the Stock JellyBean)</li>
<li>Using Deodexed XWLS8 ROM and applying the MODs on it</li>
</ul>
by virtue of which I installed Multi window on S2 successfully....and it is running great!!<br />
<br />
There are other methods too, but for that, you need a custom ROM(deodexed XXLSJ).<br />
<br />
In this post I would share both these methods of installing the Mods for Galaxy S2 for Multi Window and Ripple Lock Screen.<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxpl_QRYG0ZP6Au7jytHVNP4w45nDF9v3nOaTf6cVjrrPCueiucFmEzRHGxycfAe92z7NrA9zy6STism7M1Hrns4JoGxtcul1q3_BSmwkneKNJohZaq_j-a29bvqd7I5JDGXxRHZfxxj0/s1600/Screenshot_2013-03-09-10-58-04.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxpl_QRYG0ZP6Au7jytHVNP4w45nDF9v3nOaTf6cVjrrPCueiucFmEzRHGxycfAe92z7NrA9zy6STism7M1Hrns4JoGxtcul1q3_BSmwkneKNJohZaq_j-a29bvqd7I5JDGXxRHZfxxj0/s320/Screenshot_2013-03-09-10-58-04.png" width="192" /></a><br />
<br />
<br />
<br />
This process requires the following things in place:<br />
<ul style="text-align: left;">
<li>It was tried and tested only for the International version of galaxy S2(GT-i9100), running XWLS8 Jelly Bean 4.1.2. I'm not sure about the rest of the versions</li>
<li>The Galaxy S2 must be <b>Rooted</b></li>
<li>You must have the Clockwork Recover Mod (CWM) installed (You can download the CWM form: <a href="http://www.clockworkmod.com/rommanager">http://www.clockworkmod.com/rommanager</a>)</li>
<li>Take a NANDROID backup of your phone, just in case some unexpected problem arises</li>
<li>Ensure that the phone has atleast 85% battery charge</li>
</ul>
As usual, comes the <b>disclaimer</b>:<br />
The instructions provided in this guide are meant for reference purpose only. I will not be held liable if the device is damaged during the installation. Users must proceed at their own risk.<br />
<br />
<b>Though I have given two methods to get Multi Window for Galaxy SII, I personally prefer <i><span style="color: orange;">Method 2</span></i>.</b><br />
<br />
<b><span style="color: #0b5394; font-size: large;">Method 1: 'Installing Mods for the Stock JB firmware'</span></b><br />
<b><br /></b>
<b>Files Required:</b><br />
<b><a href="http://d-h.st/Mok">Alliance Mods for Galaxy S2</a></b><br />
<br />
Step 1: Download the Mods from <a href="http://d-h.st/Mok">MultiWindowMods</a><br />
Step 2: Place the downloaded file in your Sdcard.<br />
Step 3: Now, reboot into Recovery mode. To do this, Power off your phone, and then press the<br />
Volume Up+ Home+ Power button simultaneously.<br />
Step 4: Now, once you are in Clockwork recovery, select 'Install from Zip' option<br />
Step 5: Now, select the file that we downloaded in step 1<br />
The features will now be installed<br />
Step 6: Now, go back and select Reboot<br />
Step 7: Your phone will now reboot<br />
<br />
And, its done!! You will now be graced with a Ripple Lock screen. You now need to enable the Multi Window option from the Display Section and you are all set to boast of a Multi Window!!<br />
Also, a section called Alliance Control will be added to the Settings, wherein you can customize the lock screen and other features. Take care not to select the Alliance OTA option as it may mess up your phone.<br />
<div class="separator" style="clear: both; text-align: center;">
<b><span style="color: orange;">Snapshots from Method 1</span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGXAXcTo4wC8ezYGJiByQCc_oq3wJd84hcipib98m_5iHLZk91GaFmBb0uGX7_YKB46Clyc1gIZxCfTHfitSLRLODEqXm0H-5bYDl3gj0A2dp-G09WaU1y4CVhBg-Q71r8ZUlGIylBCsk/s1600/IMG-20130306-WA0000%5B1%5D.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGXAXcTo4wC8ezYGJiByQCc_oq3wJd84hcipib98m_5iHLZk91GaFmBb0uGX7_YKB46Clyc1gIZxCfTHfitSLRLODEqXm0H-5bYDl3gj0A2dp-G09WaU1y4CVhBg-Q71r8ZUlGIylBCsk/s400/IMG-20130306-WA0000%5B1%5D.jpg" width="400" /></a></div>
<br />
<br />
<b><span style="color: #073763; font-size: large;">Method 2: Using Deodexed XWLS8 ROM and applying Multi Window Mods</span></b><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBKUQWQ7OP8iJkLQ1DMq1jsmoqLsp4LWUC_1r3jxdlW-Rf-3Ik7rbaAWou9g9cKRcgWpFsfZCl-pEjb_qPOxszsFWLcgp3sl9vrx-9X0A4CrL3ZKUYm93X_1EX5x0D7WhZRtFvWtpc8KU/s1600/Screenshot_2013-03-09-10-56-44.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBKUQWQ7OP8iJkLQ1DMq1jsmoqLsp4LWUC_1r3jxdlW-Rf-3Ik7rbaAWou9g9cKRcgWpFsfZCl-pEjb_qPOxszsFWLcgp3sl9vrx-9X0A4CrL3ZKUYm93X_1EX5x0D7WhZRtFvWtpc8KU/s400/Screenshot_2013-03-09-10-56-44.png" width="240" /></a></div>
<b><br /></b>
<b>Files Required:</b><br />
<a href="https://content.wuala.com/contents/Tedascuen/Galaxy%20S2/GT-I9100-XWLS8-FOP-deodexed-by-tedascuen.zip?key=CjKcrbzC84Go&id=1,1602088,11-122,2179013,18" style="text-align: justify;">Deodexed XWLS8 ROM</a><br />
<a href="http://www.mediafire.com/?bllfp1bfxpmog5z" style="text-align: justify;">Multi Window Mods</a><br />
<br />
Step 1: Download the Deodexed XWLS8 ROM from <a href="https://content.wuala.com/contents/Tedascuen/Galaxy%20S2/GT-I9100-XWLS8-FOP-deodexed-by-tedascuen.zip?key=CjKcrbzC84Go&id=1,1602088,11-122,2179013,18">DeodexedXWLS8</a><br />
Step 2: Place the downloaded zip file in sdcard<br />
Step 3: Reboot into Clockwork Recovery Mode<br />
Step 4: Select install from zip, & then select the zip folder downloaded in Step 1<br />
The deodexed ROM will now be flashed<br />
Step 5: Once done, reboot the phone....you would be graced with the Ripple Lock Screen<br />
Step 6: Download the Multi Window Mod from <a href="http://www.mediafire.com/?bllfp1bfxpmog5z">Multi_Window_Mods</a><br />
Step 7: Place the zip file in sdcard and again Reboot into Clockwork recovery mode<br />
Step 8: Select install from zip, and select the zip file for mods downloaded in Step 6<br />
Step 9: The Mods will now be installed<br />
Step 10: Once done, reboot the phone<br />
<br />
Thats it!! Select the Multi Window option from Settings ->Display section and you are all ready to start enjoying the magic of Multi Window!!<br />
<br />
I preferred Method 2 over 1 for the simple reason, as I now have a deodexed ROM, which gives me greater freedom to play around with my phone, and I don't need to worry about the Alliance Mods!!<br />
<div style="text-align: center;">
<b><span style="color: orange;">Snapshots from Method 2:</span></b></div>
<div style="text-align: center;">
<b><span style="color: orange;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHG09O-grQ5SVhq4o4SpPPnEADLTHIFxBYQRcvP5BNaoD3gmIFhrFqg-Hy3I-RXWmdMD1mYz4wpZ-h-nAzY1XCUoyJGeANMVkhMJRU5FQXdovrNba3IvLVC06kNKJ2axZI7XUVHQg1Qgc/s1600/Screenshot_2013-03-09-10-56-36.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHG09O-grQ5SVhq4o4SpPPnEADLTHIFxBYQRcvP5BNaoD3gmIFhrFqg-Hy3I-RXWmdMD1mYz4wpZ-h-nAzY1XCUoyJGeANMVkhMJRU5FQXdovrNba3IvLVC06kNKJ2axZI7XUVHQg1Qgc/s400/Screenshot_2013-03-09-10-56-36.png" width="400" /></a></div>
<div style="text-align: center;">
<b><span style="color: orange;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwscNqk88QPhsEOsuxfHP72NsxOd2T1c4WlZyKjBWWKb-HHCB26ScVcvo3TgxpAXIFVdBFLqkmHdgzMychuANlBWKc1kJSBzipZF4GYZTC8OazFLEIGgm-jMRAD-IVc6CfifPsPnYalbA/s1600/Screenshot_2013-03-09-10-55-12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwscNqk88QPhsEOsuxfHP72NsxOd2T1c4WlZyKjBWWKb-HHCB26ScVcvo3TgxpAXIFVdBFLqkmHdgzMychuANlBWKc1kJSBzipZF4GYZTC8OazFLEIGgm-jMRAD-IVc6CfifPsPnYalbA/s400/Screenshot_2013-03-09-10-55-12.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
Have queries?? Stuck anywhere?? Post all the issues on <a href="http://www.compild.com/">Compild</a></div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com71tag:blogger.com,1999:blog-5359953784757764379.post-50890815036433552002012-10-02T11:53:00.003+05:302013-05-03T20:28:32.557+05:30Creating a Barcode in PHP<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0hVjXC_6W5mgVLMlw70p2aKTZAw3wcXVTZ5kSAke3tXnJ35l9TUgLPV0z9a2aI8NM4YqjKdI9E7Hx3PaE-agJHJUNBRBOI2DQ4d9ij1WWbKEy_DVwOHvwbcXkNIWTZKiPnWdFGbCY-64/s1600/barcode.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="88" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0hVjXC_6W5mgVLMlw70p2aKTZAw3wcXVTZ5kSAke3tXnJ35l9TUgLPV0z9a2aI8NM4YqjKdI9E7Hx3PaE-agJHJUNBRBOI2DQ4d9ij1WWbKEy_DVwOHvwbcXkNIWTZKiPnWdFGbCY-64/s320/barcode.PNG" width="320" /></a></div>
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;"><br /></span></span>
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;"><br /></span></span>
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">A barcode is an optical machine-readable representation of data relating to the object to which it is attached. Originally barcodes represented data by varying the widths and spacings of parallel lines, and may be referred to as linear or one-dimensional (1D).</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">A Barcode is generally used to map a product to its characteristics. For example, a barcode is commonly used to identify the product code, and map the unique code to the price of the product in the database. This barcode is a widely used technique.</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">Creating a barcode is a fairly easy job, provided you have the right font for it. I found one, with relative ease, and guess what....it was free of cost!! I have added the font file in free3of9.zip folder, which can be downloaded from the download box present in the sidebar. I really want to thank the creator of this font, for his hardwork, and also making his work available free of charge.</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">Once you have the right font, the rest is quite an easy job. we will use the basic function in PHP, viz</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;"><br /></span></span>
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">imagettftext($img, $fontsize, $angle, $xpos, $ypos, $color, $fontfile, $text);</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">Now, create a PHP file, which I have named as index.php in my case.</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;"><br /></span></span>
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">Include the following code in the file:</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">
</span></span>
<br />
<pre><?php
$number = '*8108137*';
$barcode_font = 'FRE3OF9X.TTF';
$width = 200;
$height = 80;
$img = imagecreate($width, $height);
// First call to imagecolorallocate is the background color
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
// Reference for the imagettftext() function
// imagettftext($img, $fontsize, $angle, $xpos, $ypos, $color, $fontfile, $text);
imagettftext($img, 36, 0, 10, 50, $black, $barcode_font, $number);
//imagettftext($img, 14, 0, 40, 70, $black, $plain_font, $number);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
</pre>
</div>
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">Here, in this code, the code for which barcode needs to be generated is stored in the $number variable. Care needs to be taken that the code starts and ends with an asterisk (*). The barcode scanner starts looking for an asterisk, and then scans ahead of * till it reaches the ending *.</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">For example, if the code is 1234567, it is represented as *1234567*.</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">Now, this number, or code can be passed from another page, using the GET method of PHP.</span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">Your code is now ready!! Open your project in localhost, and see your code generating a Barcode!! </span></span><br />
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;"><br /></span></span>
<span style="font-family: sans-serif;"><span style="line-height: 19.200000762939453px;">If you found the post helpful, please share!!</span></span></div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com1tag:blogger.com,1999:blog-5359953784757764379.post-1736904216298587392012-07-14T20:37:00.001+05:302014-07-30T22:02:24.043+05:30Secure Login Code using PHP and MySQL / Preventing SQL Injection using PHP<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTqwrnqSl8CriArKnZr2_VNxJVD-q2MWdpX8aacoFzlnJuR009sSFmDFdnrR7EOGrrVu-hwuHn2a2KVK2bCepTmwSStJuKePGmlyG6ffv66_79GFZP4sCNghZbkUYCz2gdTOOK_XOe5fo/s1600/sqlInjection.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTqwrnqSl8CriArKnZr2_VNxJVD-q2MWdpX8aacoFzlnJuR009sSFmDFdnrR7EOGrrVu-hwuHn2a2KVK2bCepTmwSStJuKePGmlyG6ffv66_79GFZP4sCNghZbkUYCz2gdTOOK_XOe5fo/s1600/sqlInjection.PNG" /></a></div>
Many Web pages accept parameters from web users and generate SQL queries to the database. SQL Injection is a trick to inject SQL script/command as an input through the web front end.<br />
<br />
Your application may be susceptible to SQL Injection attacks when you incorporate invalidated user input into the database queries. Particularly susceptible is a code that constructs dynamic SQL statements with unfiltered user input.<br />
<br />
<br />
<br />
<span style="background-color: white;">Consider the following example code:</span><br />
Sql DataAdapter myCommand = new SqlDataAdapter(<br />
"Select * from Users<br />
Where UserName = ' "+txtuid.Text+" ", conn);<br />
<br />
Attackers can inject SQL by terminating the intended SQL statement with the single quote character followed by a semicolon character to begin a new command and then executing the command to their choice. Consider the following character string entered into the .txtuid field.<br />
<b>' OR 1=1</b><br />
<span style="background-color: white;">This results in the following statement to be submitted to the database for execution:</span><br />
SELECT * FROM Users WHERE UserName = ' ' OR 1 = 1;<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkPW4DcmZgXM6IbpOzf_5EWwwpndaXY09AWq-jqPC-KnB_oQrZgLLTK961tsCUM6nM_4RUHKkgJmtuUwa8kh3QB1sxTM9HadahjnezqYhqNBauixppYFvXcT-_F4g2a_Wkd616vUtwEVE/s1600/securelogin.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkPW4DcmZgXM6IbpOzf_5EWwwpndaXY09AWq-jqPC-KnB_oQrZgLLTK961tsCUM6nM_4RUHKkgJmtuUwa8kh3QB1sxTM9HadahjnezqYhqNBauixppYFvXcT-_F4g2a_Wkd616vUtwEVE/s200/securelogin.gif" height="151" width="200" /></a><br />
Because 1=1 is always true, the attacker retrieves very row of data from the user table.<br />
<br />
<span style="background-color: white;">Now, to prevent such an attack, a secure login technique is required. Here, in this article, we discuss the coding of a secure login script using PHP and MySQL.</span><br />
<span style="background-color: white;"><br /></span>
<span style="background-color: white;"><br /></span>
<span style="background-color: white;">Step I: Create a database and a table 'members' in it:</span><br />
<br />
<div>
<pre class="brush:sql">CREATE TABLE `members` (
`username` varchar(20),
`password` varchar(128)
)
</pre>
<br />
<br />
Step II: Create a Login Form:<br />
<br /></div>
<div>
<pre class="brush:html"><form action="process_login.php" method="post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" value="Login" />
</form>
</pre>
<br />
<br />
Connect to MySQL Server:<br />
<br /></div>
<div>
<pre class="brush:php">$host = 'localhost'; // Host name Normally 'LocalHost'
$user = 'root'; // MySQL login username
$pass = ''; // MySQL login password
$database = 'test'; // Database name
$table = 'members'; // Members name
mysql_connect($host, $user, $pass);
mysql_select_db($database);
</pre>
<br />
<br />
Step III: Now, you need to provide mechanism to avoid SQL Injection. For this, escape special characters like ", ', \<br />
<br />
<span style="font-family: Verdana, Arial, sans-serif; font-size: 12px; line-height: 21px; text-align: -webkit-auto;">We can escape special characters (prepend backslash) using mysql_real_escape_string or addslashes functions. In most cases PHP will this do automatically for you. But PHP will do so only if the </span><strong style="border: none; font-family: Verdana, Arial, sans-serif; font-size: 12px; line-height: 21px; margin: 0px; outline: none; padding: 0px; text-align: -webkit-auto; vertical-align: baseline;">magic_quotes_gpc</strong><span style="font-family: Verdana, Arial, sans-serif; font-size: 12px; line-height: 21px; text-align: -webkit-auto;"> setting is set to On in the php.ini file.</span>
<br />
<span style="font-family: Verdana, Arial, sans-serif; font-size: 12px; line-height: 21px; text-align: -webkit-auto;">If the setting is off, we use mysql_real_escape_string function to escape special characters. If you are using PHP version less that 4.3.0, you can use the addslashes function instead.</span><br />
<span style="font-family: Verdana, Arial, sans-serif; font-size: 12px; line-height: 21px; text-align: -webkit-auto;"><br /></span></div>
<div>
<pre class="brush:php">name = mysql_real_escape_string($_POST['username']);
$password = md5($_POST['password']);
$result = mysql_query("SELECT * FROM $table WHERE username = '$username' AND password = '$password'
");
</pre>
<br />
Here, we use the MD5(Message Digest 5) Algorithm, that generates the message digest for the password. So, while writing the script for registration page, care must be taken that the md5 of the password entered by the user must be stored in the database, instead of the actual text password. <b>In a real world situation, do not use MD5, as it is no longer considered secure. Use some other secure hashing algorithm.</b><br />
<br />
Validating the login:<br />
<br /></div>
<div>
<pre class="brush:php">if(mysql_num_rows($result))
{
// Login
session_start();
$_SESSION['username'] = htmlspecialchars($username);
}
else
{
// Invalid username/password
echo '<p><strong>Error:</strong> Invalid username or password.</p>';
}
// Redirect
header('Location: http://www.example.com/loggedin.php');
exit;
</pre>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
You are done!! This code will help prevent the SQL injection problem. However, it must be noted that no script is 100% secure. So, it is advisable to provide multilevel security process, which make the login more secure.<br />
<br /></div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com9tag:blogger.com,1999:blog-5359953784757764379.post-5343796693588059712012-07-11T10:19:00.002+05:302013-05-03T20:29:12.897+05:30Auto Refresh a Web Page using AJAX<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6onHXm1TgeGrUZcxe3vqyXejZ4etdSdLEJ3imy5aRrgz5hzoKQyj9ijAaH3K5rmRfY_jmdOCcRssSdrcM7bzlji60esYfdoXxDJel1S3HhWpROBptYxQGmmjICmFnkZS1Urk3l0cRPsU/s1600/autorefresh.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="253" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6onHXm1TgeGrUZcxe3vqyXejZ4etdSdLEJ3imy5aRrgz5hzoKQyj9ijAaH3K5rmRfY_jmdOCcRssSdrcM7bzlji60esYfdoXxDJel1S3HhWpROBptYxQGmmjICmFnkZS1Urk3l0cRPsU/s320/autorefresh.PNG" width="320" /></a></div>
AJAX is nothing but Asynchronous JavaScript and XML. It is not a new programming language, but a new way to use the existing standards. It is the art of exchanging data with a server, and updating parts of a web page without reloading the whole page!!<br />
<br />
Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. JavaScript and XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.<br />
<br />
Using JavaScript for periodically refreshing a page can be quite annoying, as the entire page reloads time to time. Hence, a better option would be to use AJAX.<br />
Include the following code in the <head> section of the page....<br />
<br />
<div>
<pre><script src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script>
var auto_refresh = setInterval(
function()
{
$.ajaxSetup({ cache: false });
$('#loaddiv').fadeOut('slow').load(window.location.href).fadeIn("slow");
}, 20000);
</script>
</pre>
<br />
<br />
The section now refreshes after every 20 seconds. You can change the 20000 value to suite your requirements.<br />
You can remove the ".fadeOut('slow')" and ".fadeIn(Slow)" parts if you want the page to be refreshed unnoticed.<br />
<br />
Now, whichever section you want to be refreshed, must be included within the <b><div id="loaddiv"></b> tags as follows:<br />
<br /></div>
<div>
<pre><div id="loaddiv">
<!--Your Content goes here-->
</div>
</pre>
<br />
<br />
You are now done!! Enjoy as your page refreshes without you noticing!!<br />
<br /></div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com7tag:blogger.com,1999:blog-5359953784757764379.post-55342988432064851432012-07-08T09:42:00.002+05:302012-07-08T09:42:56.849+05:30Checking if your Computer has been violated and infected with DNS Changer<div dir="ltr" style="text-align: left;" trbidi="on">
Domain name system (DNS) is the part of the internet that links a website name (say example.com) to its numerical internet protocol equivalent (say 123.456.789.098). As the cyber world awaits Monday, when the FBI will shut down servers affected by the DNS changer malware, there is still a day to check if your system has been affected.<br />
Various cyber security firms are offering free solutions. You can visit <a href="http://www.mcafee.com/dnsdetect">www.mcafee.com/dnsdetect</a> to check if your computer is infected.<br />
You can also manually check if your DNS server has been changed.<br />
<br />
Step I: Open <b>Command Prompt</b>.<br />
Navigate to Start-> Run.<span style="background-color: white;"> Type cmd and hit enter.</span><br />
<span style="background-color: white;"><br /></span><br />
<span style="background-color: white;">StepII: (For Windows XP)Type <b>ipconfig/all</b> and hit enter.</span><br />
<span style="background-color: white;"> (For Windows 7) Type <b>ipconfig/allcompartments/all </b>and hit enter.</span><br />
<span style="background-color: white;"><br /></span><br />
<span style="background-color: white;">Step III: (For Windows XP) </span><span style="font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; orphans: 4; text-align: -webkit-auto;">The command you entered displays information about your computer’s network settings. Read the line starting with </span><tt style="border: 0px; font-size: 14px; line-height: 22px; margin: 0px; orphans: 4; outline: 0px; padding: 0px; text-align: -webkit-auto; vertical-align: baseline;"><strong style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"DNS Servers"</strong></tt><span style="font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; orphans: 4; text-align: -webkit-auto;">. There might be two or more IP addresses listed there. These are the DNS servers your computer uses. </span><strong style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin: 0px; orphans: 4; outline: 0px; padding: 0px; text-align: -webkit-auto; vertical-align: baseline;">Write down these numbers.</strong><br />
<div style="orphans: 4; text-align: -webkit-auto;">
<span style="font-family: Georgia, 'Times New Roman', Times, serif;"><span style="font-size: 14px; line-height: 22px;"><br /></span></span></div>
<div style="orphans: 4; text-align: -webkit-auto;">
<span style="font-family: Georgia, 'Times New Roman', Times, serif;"><span style="font-size: 14px; line-height: 22px;">(For Windows 7) </span></span><span style="background-color: white; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px;">The output will be very long, since Windows7 by default has support for IPv6. Most likely, you want to look for the IPv4 information under the section entitled “Ethernet adapter…”. Look for the “DNS Servers” line, and write down these numbers. There may be two IP addresses listed there.</span></div>
<div style="orphans: 4; text-align: -webkit-auto;">
<span style="background-color: white; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px;"><br /></span></div>
<div style="orphans: 4; text-align: -webkit-auto;">
<span style="background-color: white; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px;">Step IV: Check if your DNS settings are OK</span></div>
<div style="orphans: 4; text-align: -webkit-auto;">
<span style="background-color: white; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px;"><br /></span></div>
<div style="orphans: 4; text-align: -webkit-auto;">
<span style="background-color: white; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px;">Compare your DNS settings with the known malicious Rove DNS settings listed below:</span></div>
<div>
<table border="1">
<tbody>
<tr><th>Starting IP</th>
<th>Ending IP</th>
<th>CIDR</th>
</tr>
<tr>
<td>85.255.112.0</td>
<td>85.255.127.255</td>
<td>85.255.112.0/20</td>
</tr>
<tr>
<td>67.210.0.0</td>
<td>67.210.15.255</td>
<td>67.210.0.0/20</td>
</tr>
<tr>
<td>93.188.160.0</td>
<td>93.188.167.255</td>
<td>93.188.160.0/21</td>
</tr>
<tr>
<td>77.67.83.0</td>
<td>77.67.83.255</td>
<td>77.67.83.0/24</td>
</tr>
<tr>
<td>213.109.64.0</td>
<td>213.109.79.255</td>
<td>213.109.64.0/20</td>
</tr>
<tr>
<td>64.28.176.0</td>
<td>64.28.191.255</td>
<td>64.28.176.0/20</td>
</tr>
</tbody></table>
</div>
<div style="orphans: 4; text-align: -webkit-auto;">
</div>
<div style="border: 0px; clear: both; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin: 0px; orphans: 2; outline: 0px; padding: 0px; vertical-align: baseline;">
</div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 1.6em; margin-top: 1.6em; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 1.6em; margin-top: 1.6em; outline: 0px; padding: 0px; vertical-align: baseline;">
<b>What if you are infected?</b></div>
<div style="border: 0px; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 22px; margin-bottom: 1.6em; margin-top: 1.6em; outline: 0px; padding: 0px; vertical-align: baseline;">
If you computer is infected, please refer the page that l<a href="http://www.dcwg.org/fix/" style="border: 0px; color: #225e9b; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;">ist tools to clean DNS Changer</a> and other self help guides to clean your computer – http://www.dcwg.org/fix/
</div>
</div>Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com0tag:blogger.com,1999:blog-5359953784757764379.post-22948983495426001072012-07-02T12:10:00.000+05:302013-05-03T20:29:26.973+05:30How to create CAPTCHA using PHP<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="text-align: left;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi15NI6k-j40_Ofjk3h_d75yAyMjCvdQ0vTAmIxM1hlAH2G8JMwOp93ii3DqqrRdRRXdsWmoe49lX1VX82UTGJ_ENMZaz68Pd0o4MJf3q8a1k-kXIovz3Dv_vI5P27sYjCpMTbwxrxDeN8/s1600/captcha.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi15NI6k-j40_Ofjk3h_d75yAyMjCvdQ0vTAmIxM1hlAH2G8JMwOp93ii3DqqrRdRRXdsWmoe49lX1VX82UTGJ_ENMZaz68Pd0o4MJf3q8a1k-kXIovz3Dv_vI5P27sYjCpMTbwxrxDeN8/s1600/captcha.PNG" /></a></div>
<span style="font-family: inherit;">CAPTCHA: </span>
<span style="line-height: 18px;">Completely Automated Public Turing Test To Tell Computers and Humans Apart</span><span style="font-family: inherit;">.</span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><br /><span style="background-color: white; line-height: 18px;">A CAPTCHA is a program that protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot. For example, humans can read distorted text as the one shown alongside, but current computer programs can't:</span></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><span style="background-color: white; line-height: 18px;"><br /></span><span style="background-color: white; line-height: 18px;">The term CAPTCHA (for Completely Automated Public Turing Test To Tell Computers and Humans Apart) was coined in 2000 by Luis von Ahn, Manuel Blum, Nicholas Hopper and John Langford of Carnegie Mellon University.</span></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><span style="background-color: white; line-height: 18px;"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><span style="background-color: white; line-height: 18px;">Generating a simple CAPTCHA and its verification is quiet a simple task using PHP. In this post, I would do the same, but the CAPTCHA generated would be a simple one, while the reader can add his own creativity to it later!!</span></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;"><span style="background-color: white; line-height: 18px;"><br /></span></span></div>
<div style="text-align: left;">
</div>
<ul style="text-align: left;">
<li><span style="line-height: 18px;">Step I: Create a file captchaimg.php, and add the following code to it:</span></li>
</ul>
<div>
<span style="line-height: 18px;"><br /></span></div>
<div>
<pre><?php
session_start();
header("Content-Type: image/png");
$text=substr(md5(uniqid(rand(), true)),0,5);
$_SESSION["vercode"] = $text;
$height = 25;
$width = 65;
$image_p = imagecreate($width, $height);
$black = imagecolorallocate($image_p, 0, 0, 0);
$white = imagecolorallocate($image_p, 255, 255, 255);
$font_size = 14;
imagestring($image_p, $font_size, 5, 5, $text, $white);
imagejpeg($image_p, null, 80);
?>
</pre>
<br />
<br />
You can check the above file by opening it in your browser. Everytime you refresh, a new, random alphanumeric string is generated in the CAPTCHA.<br />
<ul style="text-align: left;">
<li>Step II: Create a form form.php, and add the following code to it:</li>
</ul>
</div>
<div>
<pre><?php
session_start();
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='')
{
echo '<strong>Incorrect verification code.</strong>';
} else {
// add form data processing code here
echo '<strong>Verification successful.</strong>';
};
?>
<form action="form.php" method="post">
Comment: <input type="text" name="coment">
Enter Code <img src="captchaimg.php" /><input name="vercode" type="text" />
<input name="Submit" type="submit" value="Submit" />
</form></pre>
<br />
<br />
Now, this is it!! Your basic CAPTCHA is ready!! It will look like below:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv9J4Shj3EtbN96gW6wWb4k3VN7x_r9WNt40P0X8z_Xj0URQcABEjfbZRBlfBx2BqMvF5SVt72hcfM_7dMyEu9EJe451e4IZk4-51DSM3C3RAJeoXC6bSQurVJKb529QtxGNUn_9zkE_k/s1600/c.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="59" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv9J4Shj3EtbN96gW6wWb4k3VN7x_r9WNt40P0X8z_Xj0URQcABEjfbZRBlfBx2BqMvF5SVt72hcfM_7dMyEu9EJe451e4IZk4-51DSM3C3RAJeoXC6bSQurVJKb529QtxGNUn_9zkE_k/s640/c.PNG" width="640" /></a></div>
<br />
<b style="background-color: white;"><span style="color: orange;">Another Example:</span></b><br />
For this, you need to include a font file in your project folder. I have used AngelicWar.ttf. Download the font from the download box alongside.<br />
Now, Overwrite the file captchaimg with the following code:<br />
<br />
<div>
<pre><?php
session_start();
header("Content-type: image/png");
$_SESSION["vercode"]="";
$im = imagecreate(105, 50); //Size of the image Width, Height
imagecolorallocate($im, 167, 218, 239); //Set background color
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$font = 'AngelicWar.ttf'; // You can replace font by your own
for($i=0;$i<=5;$i++) {
$numb=substr(md5(uniqid(rand(), true)),0,1);
$_SESSION["vercode"].=$numb;
$angle=rand(-25, 25);
imagettftext($im, 20, $angle, 8+15*$i, 30, $black, $font, $numb);
// Add shadow to the text
imagettftext($im, 20, $angle, 9+15*$i, 34, $grey, $font, $numb);
}
imagepng($im);
imagedestroy($im);
?>
</pre>
</div>
<br />
Now, this will result in following CAPTCHA:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT9uNSU9YOOyE_VVCH-g90WD2HoqP-d1sd_GORZWOMtwq7N6YyLXE_YRi_AlXquOKf4miXweAdnt08CyoZOa8_BQHfyj1Qn4VIvjFb52vk6jJX4BBnUE5IyeGmF_zp97f6XsfyrAIdf3Q/s1600/c2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="60" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT9uNSU9YOOyE_VVCH-g90WD2HoqP-d1sd_GORZWOMtwq7N6YyLXE_YRi_AlXquOKf4miXweAdnt08CyoZOa8_BQHfyj1Qn4VIvjFb52vk6jJX4BBnUE5IyeGmF_zp97f6XsfyrAIdf3Q/s640/c2.PNG" width="640" /></a></div>
<br />
For the following CAPTCHA use cheapink.ttf from the download box alongside.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSVo3pSczNxDTw3VHZUkzy9bCuQPTxqW4HVmFIzsbhdEehCP1pwfXAb56aUjo2j87SdhyphenhyphenJjoEUUTCpgUjIDMALdsri8kc3w84fX6lwXhUMrAatIAUILo09Pulo7-EfhA8OBxnx4SqSn30/s1600/c2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="62" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSVo3pSczNxDTw3VHZUkzy9bCuQPTxqW4HVmFIzsbhdEehCP1pwfXAb56aUjo2j87SdhyphenhyphenJjoEUUTCpgUjIDMALdsri8kc3w84fX6lwXhUMrAatIAUILo09Pulo7-EfhA8OBxnx4SqSn30/s640/c2.PNG" width="640" /></a></div>
<br />
<br />
You can enhance it by using two different strings in a single CAPTCHA image, or using some string characteristics.<br />
<br />
Want help in creating more creative CAPTCHA?? Feel free to <a href="http://ajinkyamandhare.blogspot.in/p/contact-me.html">Contact Me</a>.<br />
<br /></div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com6tag:blogger.com,1999:blog-5359953784757764379.post-17398498310128704982012-06-15T10:29:00.000+05:302013-05-03T20:29:41.891+05:30Connecting C# to MySQL database / C# connection String for MySQL<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY0dYdyJ3e9wIT4JYDlbxSntzJXX7e2yVRhyttwEVliPFd8DQdagetISr2WhYXON-FoHSsPO0O1Zc8SIi0bxPEiEEYfkBZLL0uw4RREjPQRq5Ub5WqR-z893BqWqUtRKXkax8wMITSfW8/s1600/cstomysql.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY0dYdyJ3e9wIT4JYDlbxSntzJXX7e2yVRhyttwEVliPFd8DQdagetISr2WhYXON-FoHSsPO0O1Zc8SIi0bxPEiEEYfkBZLL0uw4RREjPQRq5Ub5WqR-z893BqWqUtRKXkax8wMITSfW8/s1600/cstomysql.PNG" /></a></div>
In many cases it becomes imperative to connect C# to MySql, the prominent reason being the inherent simplicity of MySql. We have generally used the usual connection string to connect PHP to MySql. Connecting C# to MySql is similar.<br />
We first need to use the connection string to establish the connection with MySql. Then, we use the SQL queries to carry out the Creation, Insertion, Update & Delete operations.<br />
<br />
<br />
Before we do anything, first you need to download and install mysql-connector. You can get this connector from <span style="color: orange;"><a href="http://dev.mysql.com/downloads/connector/net/">MySQL :: Download Connector/Net</a>.</span><br />
<br />
Once you install this connector, you need to add it as a reference in your C# project. You can do this by navigating to <span style="color: orange;"><b>Project -> Add Reference</b></span>. Then go to the .Net tab, and search for MySql.Data, and add it as a reference.<br />
<br />
Now you need to include MySql.Data.MySqlClient at the start of the code. Add this at the start:<br />
<div>
<pre>using MySql.Data.MySqlClient;
</pre>
</div>
<br />
<br />
Now, you can use this connection string for establishing the connection:<br />
<div>
<pre>string MyConString = "SERVER=localhost;" + "DATABASE=dbname;" + "UID=root;" + "PASSWORD=\"\";";
MySqlConnection con = new MySqlConnection(MyConString);
con.Open();
</pre>
</div>
<br />
<br />
Now, you can use 'con' when you need to fire any query.<br />
<br />
Now, lets get into details of using sql queries.<br />
<br />
1. <u><b><span style="color: orange;">CREATE TABLE</span></b></u>:<br />
<br />
<div>
<pre> string query = "CREATE TABLE table_name";
MySqlCommand cmd = new MySqlCommand(query, con);
try
{
cmd.ExecuteNonQuery();
}
catch(Exception e)
{
Console.WriteLine(e);
}
</pre>
</div>
<br />
2. <u><b><span style="color: orange;">INSERT</span></b></u>:<br />
<br />
<div>
<pre> string query = "INSERT INTO table_name (attributes) VALUES(values)";
MySqlCommand cmd = new MySqlCommand(query, con);
try
{
cmd.ExecuteNonQuery();
}
catch(Exception e)
{
Console.WriteLine(e)
}
</pre>
</div>
<br />
3. <u><b><span style="color: orange;">UPDATE</span></b></u>:<br />
<br />
<div>
<pre> string query = " UPDATE table_name
SET column1=value1, column2=value2, ...
WHERE some_column=some_value";
MySqlCommand cmd = new MySqlCommand(query, con);
try
{
cmd.ExecuteNonQuery();
}
catch(Exception e)
{
Console.WriteLine(e)
}
</pre>
</div>
<br />
4. <u><b><span style="color: orange;">DELETE</span></b></u>:<br />
<br />
<div>
<pre> string query = "DELETE FROM table_name WHERE some_column=some_value";
MySqlCommand cmd = new MySqlCommand(query, con);
try
{
cmd.ExecuteNonQuery();
}
catch(Exception e)
{
Console.WriteLine(e)
}
</pre>
</div>
<br />
5. <u><b><span style="color: orange;">SELECT</span></b></u>:<br />
<br />
<div>
<pre> MySqlCommand query = new MySqlCommand("Select * FROM `table_name` where
CONDITION, con);
MySqlDataReader reader = con.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetString("column_name"));
}
</pre>
</div>
<br />
Finally, you need to close the connection, after you finish executing the queries. You can do this by writing:<br />
<div>
<pre>con.Close();
</pre>
</div>
<br />
<br />
<br /></div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com1tag:blogger.com,1999:blog-5359953784757764379.post-50656209779930715012012-06-01T13:08:00.000+05:302013-05-03T20:29:56.020+05:30Generating a Unique Hardware Fingerprint for Software Licensing<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
Generating a hardware fingerprint is the most commonly sought technique to ensure security in case of softwares. There can be various methods of generating the hardware fingerprint, using different languages. However, the important thing to decide is, which devices to consider while generating the fingerprint.<br />
<br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">For licensing purposes, the best and secure way is to generate a unique key for the client's machine and provide a corresponding license key for that key. The key can be generated using the unique id of the client's computer motherboard, BIOS and processor. When you get these IDs, you can generate any key of your preferable format.</span>
<br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br /></span>
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">In this post, I will get into the details of generating the unique fingerprint for the user's system.</span><br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br /></span>
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">Step I: Adding References:</span><br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br /></span>
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">First of all, you need to add the following references to your project.</span><br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">1. System.Drawing</span><br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">2. System.Management</span><br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">3. System.Windows.Forms</span><br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">For doing this, navigate to Project in the Menu Bar--> Add References-->.Net</span><br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br /></span>
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">Step II: Starting to Code</span><br />
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;"><br /></span>
<span style="background-color: white; font-family: Verdana, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto;">Add the following code at the start.</span><br />
<div>
<pre>using System;
using System.Threading;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Resources;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Data;
using System.Drawing;
namespace Aj_fingerprint
{
public class Aj_fp
{
public static void Main(string[] args)
{
Aj_Fingerprint f = new Aj_Fingerprint();
string fp = f.Value();
Console.WriteLine(fp);
Console.ReadLine();
}
}
public class Aj_Fingerprint
{
public string Value()
{
return pack(cpuId()+ biosId()+ diskId()+ baseId()+ videoId()+ macId());
}
private string biosId()
{
return identifier("Win32_BIOS", "Manufacturer")
+ identifier("Win32_BIOS", "SMBIOSBIOSVersion")
+ identifier("Win32_BIOS", "IdentificationCode")
+ identifier("Win32_BIOS", "SerialNumber")
+ identifier("Win32_BIOS", "ReleaseDate")
+ identifier("Win32_BIOS", "Version");
}
private string cpuId()
{
string retVal = identifier("Win32_Processor", "UniqueId");
if (retVal == "")
{
retVal = identifier("Win32_Processor", "ProcessorId");
if (retVal == "")
{
retVal = identifier("Win32_Processor", "Name");
if (retVal == "")
{
retVal = identifier("Win32_Processor", "Manufacturer");
}
retVal += identifier("Win32_Processor", "MaxClockSpeed");
}
}
return retVal;
}
private string diskId()
{
return identifier("Win32_DiskDrive", "Model")
+ identifier("Win32_DiskDrive", "Manufacturer")
+ identifier("Win32_DiskDrive", "Signature")
+ identifier("Win32_DiskDrive", "TotalHeads");
}
private string pack(string text)
{
string retVal;
int x = 0;
int y = 0;
foreach (char n in text)
{
y++;
x += (n * y);
}
retVal = x.ToString() + "00000000";
return retVal.Substring(0, 8);
}
private string videoId()
{
return identifier("Win32_VideoController", "DriverVersion")
+ identifier("Win32_VideoController", "Name");
}
private string baseId()
{
return identifier("Win32_BaseBoard", "Model")
+ identifier("Win32_BaseBoard", "Manufacturer")
+ identifier("Win32_BaseBoard", "Name")
+ identifier("Win32_BaseBoard", "SerialNumber");
}
private string macId()
{
return identifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled");
}
private string identifier(string wmiClass, string wmiProperty)
{
string fprint = "";
System.Management.ManagementClass aj_mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection aj_moc = aj_mc.GetInstances();
foreach (System.Management.ManagementObject aj_mo in aj_moc)
{
if (fprint == "")
{
try
{
fprint = aj_mo[wmiProperty].ToString();
break;
}
catch
{ }
}
}
return fprint;
}
private string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
{
string fprint = "";
System.Management.ManagementClass aj_mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection aj_moc = aj_mc.GetInstances();
foreach (System.Management.ManagementObject aj_mo in aj_moc)
{
if (aj_mo[wmiMustBeTrue].ToString() == "True")
{
if (fprint == "")
{
try
{
fprint = aj_mo[wmiProperty].ToString();
break;
}
catch
{ }
}
}
}
return fprint;
}
}
}
</pre>
<br />
<br />
Now, you can use this unique hardware fingerprint in further hashing, to authenticate the user system!!<br />
<br />
<br /></div>
<br />
<div>
You can
<a href="http://ajinkyamandhare.blogspot.in/p/contact-me.html" rel="author">Contact Me</a> for further assistance.
</div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com2tag:blogger.com,1999:blog-5359953784757764379.post-64992865187147532302012-05-01T18:46:00.002+05:302013-05-03T20:30:09.433+05:30Solution for "Installation Error 0X80004002"<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: black;">
I was having a tough time installing <b>Google Drive</b>. When the setup was run, it gave an error message saying <b>Google Update Installation failed, with error 0X80004002</b>. This error is very common & occurs while installing Google products, like Chrome, Drive.</div>
<div style="color: black;">
I tried to search for the solution but in vain. So I took a seemingly daring way, to solve this problem, and guess what...it worked!!!</div>
<div style="color: black;">
Though this seems to be a crude way, it worked for me:</div>
<div style="color: black;">
<br /></div>
<div style="color: black;">
1. I Uninstalled all the Google related softwares from my PC, like Chrome, GTalk, Google Earth, Picasa.</div>
<div style="color: black;">
2. Then open Run, and type <b>regedit</b>. This opens the Registry Editor.</div>
<div style="color: black;">
3. Browse to <b>HKEY_CURRENT_USER</b> in the side bar.</div>
<div style="color: black;">
4. Browse <b>Software</b>, and look for <b>Google</b>.</div>
<div style="color: black;">
5. Right Click, and select <b>DELETE</b>.</div>
<div style="color: black;">
6. Now close the Registry Editor, and try to install the Google related application again.</div>
<div style="color: black;">
<br /></div>
<div style="color: black;">
Had a tough time while reinstalling all my other Google applications though!!</div>
<div style="color: black;">
<br /></div>
<div style="color: black;">
<b>Please contribute, if you have any better solution!!</b></div>
<div style="color: black;">
<br /></div>
<div>
<div style="color: black;">
<b>For me, it worked...hope it works for you!!</b></div>
<div style="color: black;">
<b><br /></b></div>
</div>
<div style="color: black;">
<br /></div>
<br />
<div>
You can
<a href="http://ajinkyamandhare.blogspot.in/p/contact-me.html" rel="author">Contact Me</a> for further assistance.
</div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com4tag:blogger.com,1999:blog-5359953784757764379.post-10344375564077118102012-03-31T17:12:00.000+05:302013-05-03T20:30:24.784+05:30Sending email using PHP...(PHPMailer)<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #444444;">
<div class="separator" style="clear: both; text-align: center;">
</div>
Sending emails using PHP is an easy task...Just a few steps and you are through!!</div>
<br />
<b style="color: red;">Step I:</b> <b><u style="color: orange;">Download PHPMailer</u></b><br />
<div style="color: #444444;">
The very first thing that needs to be done is, downloading the PHPMailer package. This package contains all the methods for sending simple mails, to sending mails with attachments!!</div>
<div style="color: #cccccc;">
<span style="color: #444444;">You can download the package from:</span> <b style="color: orange;"><a href="http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/">PHPMailer</a></b></div>
<br />
<b style="color: red;">Step II:</b> <u style="color: orange;"><b>Starting to Code</b></u><br />
<div style="color: #444444;">
Create a new php file test.php and copy the following code:</div>
<div style="color: #444444;">
(Note: test.php file should be in the same folder as the extracted PHPMailer package) </div>
<br />
<div>
<textarea cols="80" readonly="readonly" rows="20" style="background-image: url('http://i1144.photobucket.com/albums/o492/ajinkyamandhare/aj_textarea.png'); padding-left: 40px;" tabindex="4" wrap="virtual"><?php
require("class.phpmailer.php"); //You need to include the PHPMailer class
$mailer = new PHPMailer(); //Create an object of PHPMailer class
$mailer->IsSMTP(); //It uses the SMTP method...
//You can also use mail(), sendmail()
$mailer->Host = "smtp.gmail.com:587";
$mailer->SMTPAuth = TRUE;
$mailer->Username = "sender@gmail.com"; // Change this to your gmail adress
$mailer->Password = "sender_password"; // Change this to your gmail password
$mailer->From = "sender@gmail.com"; // Change this to your gmail adress
$mailer->FromName = "Sender"; // This is the from name in the email
$mailer->Body = "This is the main body from Sender";
$mailer->Subject = "Sender Subject";
$mailer->AddAddress("receiver_mail_address");// This is where you put the email
//adress of the person you want to mail
if(!$mailer->Send())
{
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
</textarea><br />
<br />
<div style="color: #444444;">
The above code uses the gmail SMTP server...You have to mention the username and password of your gmail account!!</div>
<div style="color: #444444;">
<br /></div>
<div style="color: #444444;">
This is it!! You are now all ready to send mail!!</div>
<br />
<span style="color: orange;">My next post will include sending attachments in emails....and also using mail() method!! So, keep visiting!! </span></div>
<br />
<div>
You can
<a href="http://ajinkyamandhare.blogspot.in/p/contact-me.html" rel="author">Contact Me</a> for further assistance.
</div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com1tag:blogger.com,1999:blog-5359953784757764379.post-39903431731011121352012-02-07T17:11:00.000+05:302013-09-09T21:58:08.539+05:30Macromedia Flash 8<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #999999; font-family: inherit;">
</div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;">
<span style="font-size: large;">Flash is a drawing and animation package designed
to work with vector graphics. It creates animations which can include sounds,
music and interactivity, and which are optimised for use on the web. Hence, the
files it produces are small and designed for streaming. Furthermore, all the
elements which form part of a flash movie are embedded within the movie. This
means that, unlike a standard web page which relies on the fonts and resources
on the client machine, as long as the user has the flash player installed, the
movie will play exactly as you design it. </span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"> The default file extension for a
Flash file is .fla. Flash movie files can also be published in .htm, .swf,
.jpg, .exe, .png or as a projector file.</span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div style="color: red; font-family: inherit; text-align: justify;">
<span style="font-size: large;"><u><b>Layout:</b></u></span></div>
<div style="color: #999999; font-family: inherit; margin-left: 0.25in; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><br /></span></div>
<div style="color: orange; font-family: inherit; margin-left: 0.25in; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;">§<span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;">
</span><b>Toolbox:</b></span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">The toolbox contains all tools necessary for drawing, viewing,
coloring and modifying your objects. Each tool in the toolbox comes with a
specific set of options to modify that tool. The diagram below outlines the
grouping of tools.</span></div>
<a name='more'></a><div style="font-family: inherit;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Arrow
tool:</b></span></div>
<div class="MsoListParagraphCxSpLast" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It is used to select a single or a group of
objects. </span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Lasso tool:</b></span></div>
<div class="MsoListParagraphCxSpLast" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It is used to select objects by drawing either
freehand or straight-edged selection area.</span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Text tool
(“A”):</b></span></div>
<div class="MsoListParagraphCxSpLast" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It is used to include custom text with various
options like selecting a font, colour, style, etc.</span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Line
tool:</b></span></div>
<div class="MsoListParagraphCxSpLast" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It is used to draw a line with options of line
width and style.</span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Oval
tool:</b></span></div>
<div class="MsoListParagraphCxSpLast" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It is used to draw an oval object. Ovals can be
filled with colours and outlines can be customized.</span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Rectangle
tool:</b></span></div>
<div class="MsoListParagraphCxSpMiddle" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It is used to draw a rectangular object.</span></div>
<div class="MsoListParagraphCxSpMiddle" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpMiddle" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Pencil
tool:</b></span></div>
<div class="MsoListParagraphCxSpLast" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">The Pencil tool is used to draw lines, shapes or
freehand forms. The pencil tool has three modifiers: straighten, smooth and ink. Flash straightens
or smoothens the freehand drawing made by this tool.</span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Brush
tool:</b></span></div>
<div class="MsoListParagraphCxSpLast" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">The Brush tool allows you to draw brush-like
strokes for creating special effects, including calligraphic effects and
paintings with an image. The brush tool has the following modifiers: paint
options, fill colour, gradient, brush size, brush shape, lock fill.</span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="color: orange; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b>Paint
Bucket tool:</b></span></div>
<div class="MsoListParagraphCxSpMiddle" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It is used to change the colour of the existing
paint and fill empty areas surrounded by lines. </span></div>
<div class="MsoListParagraphCxSpMiddle" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<div style="color: orange;">
<span style="font-size: large;"><br /></span></div>
<div style="color: orange;">
<span style="font-size: large;"><b>Inkbottle
tool:</b></span></div>
</div>
<div class="MsoListParagraphCxSpMiddle" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It allows to stroke lines and shapes with only
solid colours but no with no gradients or bitmaps.</span></div>
<div class="MsoListParagraphCxSpMiddle" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpMiddle" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify; text-indent: -0.25in;">
<span style="font-size: large;"><b><span style="-moz-font-feature-settings: normal; -moz-font-language-override: normal; font-size-adjust: none; font-stretch: normal; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"> </span></b><b style="color: orange;">Eraser
tool:</b></span></div>
<div class="MsoListParagraphCxSpMiddle" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;">It erases lines and fills. It can also erase
selected items such as only lines or only fills, etc.</span></div>
<div class="MsoListParagraphCxSpLast" style="color: #999999; font-family: inherit; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div style="color: red; font-family: inherit; text-align: justify;">
<span style="font-size: large;"><u><b>Timeline:</b></u></span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-size: large;">The
timeline indicates what frame you are at and also indicates the number of
frames in your movie. Within the timeline you will find layers - you can have
any number of layers within a movie and it is within these layers that you put your
graphics, text, and sounds. </span><br />
</div>
<div style="color: red; font-family: inherit; text-align: justify;">
<span style="font-size: large;"><u><b>Work Area:</b></u></span></div>
<div class="MsoNormal" style="color: #999999; font-family: inherit; line-height: normal; margin-bottom: 0.0001pt;">
<span style="font-size: large;">The
Work Area is not viewable when you play your movie, so it is a place to work on
objects or if you want your objects to “fly in” to your movie then start them
from the Work Area.</span></div>
<div style="color: red; font-family: inherit; text-align: justify;">
<span style="font-size: large;"><br /></span><br />
<span style="font-size: large;"><u><b>Stage:</b></u></span></div>
<div style="color: #999999; font-family: inherit; text-align: justify;">
<span style="font-size: large;">The Stage is where all
viewable objects lie. Anything on the stage is seen by the user and will be
seen in the animation. </span></div>
<div style="color: #999999; font-family: inherit; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; font-family: inherit; text-align: center;">
<span style="font-size: large;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgonbSQtWytcJAH6w_9e_um7xctgh3zOEXs9uzu2Y3piM_c-cxu7OAr0Z8EBv0AP47-uDVPwj6BT9mQwbZdvVvwV8sNBqPVWQqSDclpvjA37EBo9lKwTc7DILywwI9j_RILt2dtzlrrj-I/s1600/flash8.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgonbSQtWytcJAH6w_9e_um7xctgh3zOEXs9uzu2Y3piM_c-cxu7OAr0Z8EBv0AP47-uDVPwj6BT9mQwbZdvVvwV8sNBqPVWQqSDclpvjA37EBo9lKwTc7DILywwI9j_RILt2dtzlrrj-I/s640/flash8.JPG" width="640" /></a></span></div>
<div style="color: #999999; font-family: inherit; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com0tag:blogger.com,1999:blog-5359953784757764379.post-56533738849753519412012-02-05T12:38:00.000+05:302013-09-09T21:58:08.542+05:30Autodesk MAYA<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: large;"><br /></span><br />
<div style="color: orange; margin: 0in 0in 0.0001pt; text-align: justify;">
<span style="font-size: large;"><u><b><span style="font-family: Cambria, serif;">Introduction:</span></b></u></span></div>
<div style="margin: 0in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div style="color: #444444; margin: 0in 0in 0.0001pt; text-align: justify; text-indent: 0.5in;">
<span style="font-family: Cambria, serif; font-size: large;">Maya is the
3-D animation software that provides a number of tools for creating complex
characters and animations. Maya's powerful feature set gives us the flexibility
to create any kind of animation. The functionality of the Maya software
can be extended with the use of MEL (Maya embedded language). MEL can be used
to customize the user interface and write scripts and macros. </span></div>
<div style="color: #444444; margin: 0in 0in 0.0001pt; text-align: justify; text-indent: 0.5in;">
<span style="font-family: Cambria, serif; font-size: large;">Maya can
create objects, lights, cameras and textures. Any object, light, camera,
or just any entity can be animated by changing the value of its parameters in
time. We can use Maya, to create effects or animations or movies, commercials,
architectural animation and forensic animation.</span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal" style="color: orange; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><u><b><span style="font-family: Cambria, serif;">Interface:</span></b></u></span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.25in;">
<span style="font-family: Cambria, serif; font-size: large;">Maya user interface
looks provides a large number of functions and the scope to add more functions
to the user interface which provides the real flexibility to the program. Along
with the common functions there are set of functions dedicated to a more
specific task like modeling, texturing, animation, rendering etc. The default
Maya user interface can be divided into the following sections.</span></div>
<ul style="color: red;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Main Menu Bar</span></b></span></li>
</ul>
<div class="paragraph" style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">Tools and items are
accessible from pull down menus located at the top of the user interface. In
Maya, menus are grouped into menu sets. These menu sets are accessible from the
Main Menu bar.</span></div>
<div class="paragraph" style="color: #999999; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Status Line</span></b></span></li>
</ul>
<div class="paragraph" style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">The Status Line, located
directly below the Main Menu bar, contains a variety of items, most of which
are used while modeling or working with objects within Maya. Many of the Status
Line items are represented by a graphical icon. The icons save space in the
Maya interface and allow for quick access to tools used most often.</span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Shelf</span></b></span></li>
</ul>
<div style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">It contains different tools and
commands which are used to organize commonly used functions and tools into
groups. Different shelves can be created for different functions like modeling,
animation, texturing etc with the required tools for each function.</span></div>
<div style="color: #999999; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Tool Box</span></b></span></li>
</ul>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">Maya Tool Box contains common
tools as well as layout buttons for changing views and layouts. The tool box
contains: </span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">- Select tool to select a
particular object or a group of objects together. </span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">- Lasso tool is used to draw
a free hand border around the objects to be selected. </span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">- Move, Rotate and Scale
tools are used for transforming objects in Maya. </span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">- Soft Modification tool is
used to select the sub-object elements and modify them by </span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;"> moving, rotating or scaling in a way that the
neighboring sub-objects also get affected </span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;"> by this deformation with the effect being an
inverse of distance from the primary </span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;"> selected sub-objects.</span></div>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">- Last Selected tool section
shows the last used tool for easy access. </span></div>
<div style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">- Single Perspective view button
lets you view the workspace as a single large view from a single perspective. </span></div>
<div style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">- Four Views can be used to view the
workspace in four sections with each section containing the three orthographic
views top, side and front and a perspective view respectively. </span></div>
<div style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">Other combination options below
these tools are used to divide the workspace into different section in such a
way that one section contains the view of the scene and other contains an
animation or rendering editor so that you can edit the attributes and watch the
results simultaneously. </span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Workspace</span></b></span></li>
</ul>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">The Workspace displays by
default in a perspective window or panel. The purpose of using workspace is to
view your scene. The workspace can be divided into sections to accommodate the
orthographic and perspective views of the scenes as well as the different
editors for animation, texturing and rendering etc. </span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Panel Menus</span></b></span></li>
</ul>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">Every view panel has a common
set of menus at the top. </span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Time Slider
& Range Slider</span></b></span></li>
</ul>
<div style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">The Two Sliders are for controlling
the frames in your animation. The Time Slider includes the playback buttons and
the current time indicator. The Range slider includes start and end times
and allows animators to focus on a specific part of the animation.</span></div>
<div style="color: #999999; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Command Line</span></b></span></li>
</ul>
<div style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">The command Line lets you enter the
MEL (Maya embedded Language) commands to perform various functions. The left
side is where you can type MEL commands and the right half displays system
responses, error messages, and warnings. </span></div>
<div style="color: #999999; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Help Line</span></b></span></li>
</ul>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">Like several other
applications, you can look at the help line for descriptions, instructions, and
other useful information. While a tool is selected, the helpline gives out a
brief description for "how to" and "what for".</span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Channel box</span></b></span></li>
</ul>
<div style="color: #444444; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">The Channelbox is on the right side of the
screen. In this menu you will find all the properties of selected objects, and
you can change those properties. If you apply a certain command on an object,
Maya will remember this. This is called the history of an object and that is
also shown here. </span></div>
<div style="color: #999999; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<ul style="color: red; margin-top: 0in;" type="disc">
<li class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; text-align: justify;"><span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Layer editor </span></b></span></li>
</ul>
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">It helps in working with
different layers in an animation. Objects can be placed in different layers and
can be edited using this tool. </span></div>
<div style="color: #999999; margin: 0in 0in 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal" style="color: orange; line-height: normal; margin-bottom: 6pt; text-align: justify;">
<span style="font-size: large;"><u><b><span style="font-family: Cambria, serif;">Components:</span></b></u></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: red; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Fluid
Effects </span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">A realistic fluid
simulator effective for simulating smoke, fire, clouds and explosions.</span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: red; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Classic
Cloth </span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">Cloth simulation
to automatically simulate clothing and fabrics moving realistically over an
animated character. </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;"><span style="color: red;">Fur</span>
</span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">Animal fur simulation
similar to Maya Hair. It can be used to simulate other fur-like objects, such
as grass. </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;"><span style="color: red;">Hair</span>
</span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">A simulator for
realistic-looking human hair implemented using curves and Paint Effects. These
are also known as dynamic curves. </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: red; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Maya
Live </span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">A set of motion
tracking tools for CG matching to clean plate footage. </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;"><span style="color: red;">nCloth</span>
</span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #999999; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;"><span style="color: #444444;">nCloth is the
first implementation of Maya Nucleus, Autodesk's simulation framework. It gives
the artist further control of cloth and material simulations.</span> </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;"><span style="color: red;">nParticle</span>
</span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">nParticle
is addendum to Maya Nucleus toolset. nParticle is for simulating a wide range
of complex 3D
effects, including liquids, clouds, smoke, spray, and dust. </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;"><span style="color: red;">MatchMover</span>
</span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">This enables
compositing of CGI elements with motion data from video and film sequences. </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: #999999; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;"><span style="color: red;">Composite</span>
</span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 6pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">It is an interactive </span><span style="font-size: large;"><a href="http://en.wikipedia.org/wiki/Node"><span style="font-family: Cambria, serif;">node</span></a></span><span style="font-family: Cambria, serif; font-size: large;"> based film </span><span style="font-size: large;"><a href="http://en.wikipedia.org/wiki/Composing"><span style="font-family: Cambria, serif;">composing</span></a></span><span style="font-family: Cambria, serif; font-size: large;"> solution</span><span style="font-family: Cambria, serif; font-size: large;">. </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoListParagraph" style="color: red; line-height: normal; margin: 0in 0in 0.0001pt 0.25in; text-align: justify;">
<span style="font-size: large;"><b><span style="font-family: Cambria, serif;">Camera
Sequencer </span></b></span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #444444; line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-align: justify;">
<span style="font-family: Cambria, serif; font-size: large;">Camera
Sequencer is used to layout multiple camera shots and manage them in one animation
sequence. </span></div>
<span style="color: #999999; font-size: large;">
</span><br />
<div class="MsoNormal" style="color: #999999; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal" style="color: orange; line-height: normal; margin: 6pt 0in 0.0001pt; text-align: justify;">
<span style="font-size: large;"><u><b><span style="font-family: Cambria, serif;">Maya
Embedded Language:</span></b></u></span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin-bottom: 0.0001pt; text-align: justify;">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal" style="color: #999999; line-height: normal; margin-bottom: 0.0001pt; text-align: justify; text-indent: 0.5in;">
<div style="color: #444444;">
<span style="font-family: Cambria, serif; font-size: large;">Maya</span><span style="font-family: Cambria, serif; font-size: large;">
has its very own cross-platform scripting language called Maya Embedded
Language. MEL is used not only for scripting, but also as a means to customize
the core functionality of the software, since much of the tools and commands
used are written in it. Code can be used to engineer modifications, </span><span style="font-size: large;"><a href="http://en.wikipedia.org/wiki/Plug-in_%28computing%29" title="Plug-in (computing)"><span style="font-family: Cambria, serif; text-decoration: none;">plug-ins</span></a></span><span style="font-family: Cambria, serif; font-size: large;"> or be </span><span style="font-size: large;"><a href="http://en.wikipedia.org/wiki/Code_injection" title="Code injection"><span style="font-family: Cambria, serif; text-decoration: none;">injected</span></a></span><span style="font-family: Cambria, serif; font-size: large;">
into </span><span style="font-size: large;"><a href="http://en.wikipedia.org/wiki/Run-time_system" title="Run-time system"><span style="font-family: Cambria, serif; text-decoration: none;">runtime</span></a></span><span style="font-family: Cambria, serif; font-size: large;">.
Outside these superficial uses of the language, user interaction is recorded in
MEL, allowing even inexperienced users to implement </span><span style="font-size: large;"><a href="http://en.wikipedia.org/wiki/Subroutines" title="Subroutines"><span style="font-family: Cambria, serif; text-decoration: none;">subroutines</span></a></span><span style="font-family: Cambria, serif; font-size: large;">.</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYebplJT0a1muh2zQz2QzfKaEJ43T3sLaLOWJECTYW2Wi2_7h2Z31sRbOmEiVKHVqByEnZrdImbjt-4M-2B_Z18KneZjrW-UXXbGbtagbbpZsc00Bw9zUDnR6-KKrtxzXZqPer_HHNY8s/s1600/maya.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="497" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYebplJT0a1muh2zQz2QzfKaEJ43T3sLaLOWJECTYW2Wi2_7h2Z31sRbOmEiVKHVqByEnZrdImbjt-4M-2B_Z18KneZjrW-UXXbGbtagbbpZsc00Bw9zUDnR6-KKrtxzXZqPer_HHNY8s/s640/maya.JPG" width="640" /></a></div>
</div>
</div>Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com0tag:blogger.com,1999:blog-5359953784757764379.post-24088661717557082212012-02-03T17:39:00.002+05:302013-05-03T20:30:44.277+05:30Client Server Chat<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<span style="background-color: white; font-family: Verdana, sans-serif; font-size: 12px; line-height: 20px; text-align: -webkit-auto;">In this tutorial we will learn how to write a simple client server chat program in java. We will right both the server and client side of this program. One of the ways computers can communicate to each other through the internet is by using TCP/IP.</span>
</div>
<div>
<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">A </span><span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">network socket</span><span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;"> is an endpoint of an </span>inter-process<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;"> </span>communication flow<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;"> across a </span>computer network<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">. Today, most communication between computers is based on the </span>Internet Protocol<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">; therefore most network sockets are </span><span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">Internet sockets</span><span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">.</span>
</div>
<div>
<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">A </span><span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">socket address</span><span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;"> is the combination of an </span>IP address<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;"> and a </span>port number<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">, much like one end of a telephone connection is the combination of a phone number and a particular extension. Based on this address, internet sockets deliver incoming data packets to the appropriate application </span>process<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;"> or </span>thread<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;">.</span>
</div>
<div>
<span style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto;"><br /></span></div>
<div>
<div style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; margin-bottom: 0.5em; margin-top: 0.4em; text-align: -webkit-auto;">
An Internet socket is characterized by a unique combination of the following:</div>
<ul style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px; list-style-image: url(data:image/png; list-style-type: square; margin: 0.3em 0px 0px 1.6em; padding: 0px; text-align: -webkit-auto;">
<li style="margin-bottom: 0.1em;">Local socket address: Local IP address and port number</li>
<li style="margin-bottom: 0.1em;">Remote socket address: Only for established TCP sockets. As discussed in the client-server section below, this is necessary since a TCP server may serve several clients concurrently. The server creates one socket for each client, and these sockets share the same local socket address.</li>
<li style="margin-bottom: 0.1em;"><span style="color: black;">Protocol: A transport protocol (e.g., TCP, UDP, raw IP, or others). TCP port 53 and UDP port 53 are consequently different, distinct sockets.</span></li>
</ul>
<div style="text-align: -webkit-auto;">
<span style="font-family: sans-serif; font-size: x-small;"><span style="line-height: 19px;"><br /></span></span></div>
</div>
<div style="text-align: -webkit-auto;">
<span style="font-family: sans-serif; font-size: x-small;"><span style="line-height: 19px;">So, now lets get started with the actual code...</span></span></div>
<ul style="color: orange; text-align: left;">
<li><u><b>Client.java</b></u>:</li>
</ul>
<div>
<pre>import java .io.*;
import java.net.*;
public class Client
{
Socket soc;
BufferedReader inFromUser,inFromServer;
PrintWriter outToServer;
String str;
public Client()
{
try
{
soc=new Socket(InetAddress.getLocalHost(),9999);
inFromUser=new BufferedReader(new InputStreamReader(System.in));
outToServer=new PrintWriter(soc.getOutputStream(), true);
System.out.println("Client Started");
while(true)
{
str=inFromUser.readLine();
outToServer.println(str);
new InnerClient();
}
}
catch (Exception e){e.printStackTrace();}
}
class InnerClient extends Thread
{
String str1;
InnerClient()
{
try
{inFromServer=new BufferedReader(new InputStreamReader(soc.getInputStream()));
start();
}
catch (Exception e){e.printStackTrace();}
}
public void run()
{
try
{
while(true)
{
str1=inFromServer.readLine();
System.out.println("Server says : " +str1);
}
}
catch (Exception e){e.printStackTrace();}
}
}
public static void main(String args[])
{
new Client();
}
}
</pre>
</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<ul style="color: orange; text-align: left;">
<li><u><b>Server.java</b></u>:</li>
</ul>
<pre>import java.io.*;
import java.net.*;
public class Server extends Thread
{
ServerSocket ss;
Socket soc;
BufferedReader inFromUser,inFromClient;
PrintWriter outToClient;
String str;
public Server()
{
try
{
System.out.println("Chat Server");
ss=new ServerSocket(9999);
System.out.println("Server started.Wawiting for Client......");
soc=ss.accept();
System.out.println("client connected.");
inFromUser= new BufferedReader(new InputStreamReader(soc.getInputStream()));
start();
new InnerServer();
}
catch (Exception e) {e.printStackTrace();}
}
public void run()
{
try
{
while(true)
{
str= inFromUser.readLine();
System.out.println("Client says:"+str);
}
}
catch (Exception e) {e.printStackTrace();}
}
class InnerServer
{
String str1;
InnerServer()
{
try
{
inFromClient=new BufferedReader(new InputStreamReader(System.in));
outToClient=new PrintWriter(soc.getOutputStream(),true);
while(true)
{
str1=inFromClient.readLine();
outToClient.println(str1);
}
}
catch(Exception e){e.printStackTrace();}
}
}
public static void main(String args[])
{
new Server();
}
}
</pre>
<br />
<br />
<br />
<span style="color: orange;"><i><b>Note: If you want to implement the Server & Client on Different PC's then the only change required is changing the InetAddress.getLocalHost() in Client.java to the IP address of the Server PC!!</b></i></span><br />
<br />
<span style="color: orange;"><i><b><u style="color: red;">SNAPSHOTS OF SERVER & CLIENT SIDES</u> </b></i></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkFhMA2S8J2_8p5dJ7UR_qDUSfaXEdJf20jBoD-xxnNw9w4M7SdlJnQqFEJgifikmUcfE1cl3naidKrTl3RbPu2cZr-SbRUhLotPKPG5hDOp1_qioCPB9fmKWI5hKPIVhN5iZRXC7Az-A/s1600/client+chat+server.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="311" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkFhMA2S8J2_8p5dJ7UR_qDUSfaXEdJf20jBoD-xxnNw9w4M7SdlJnQqFEJgifikmUcfE1cl3naidKrTl3RbPu2cZr-SbRUhLotPKPG5hDOp1_qioCPB9fmKWI5hKPIVhN5iZRXC7Az-A/s640/client+chat+server.JPG" width="640" /></a></div>
<span style="color: orange;"><i><b> </b></i>
</span>
</div>
<br />
<div>
You can
<a href="http://ajinkyamandhare.blogspot.in/p/contact-me.html" rel="author">Contact Me</a> for further assistance.
</div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com3tag:blogger.com,1999:blog-5359953784757764379.post-56417785301343734332012-01-26T09:23:00.000+05:302013-03-31T10:17:47.169+05:30...straight from the heart of an INDIAN<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<br /></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">“With the dawn of a new
day, came a new stage,</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">With determined
agitation, we broke a white cage,</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">India rose to freedom,
when the world was asleep,</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">The jailor had to back
off, before our leap.”</span></i></div>
<div class="MsoNormal" style="color: #444444;">
<span style="font-size: 13pt; line-height: 115%;">At the dawn
of history, India started on her quest, and trackless centuries are filled with
her striving, and the grandeur of her success and her failures. Through good
and ill fortune alike, she has never lost her sight of that quest, or forgotten
the ideals, which gave her the strength. The achievement which we celebrate
today is but a step, an opening of opportunity, to the greater triumphs and
achievements that await us. Are we brave enough and wise enough to grasp this
opportunity and accept the challenge of the future? What exactly does ‘Freedom’
mean to us?</span></div>
<div class="MsoNormal" style="color: #444444;">
<span style="font-size: 13pt; line-height: 115%;">Freedom does
not merely mean breaking the bondage of the oppressor by the oppressed. But it
has a rather significant appeal to break off the internal bondages, of thought,
knowledge, customs and traditions. The greatest freedom, is the freedom from
all prejudices, preconceived notions, conditioning, ideologies, conflicting
desires, hatred & anger- until you have achieved awareness of pure
consciousness- you cannot call yourself free, you are not independent. Once you
have that awareness, you realize what freedom is…what Independence means</span><span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;">‼</span><span style="font-size: 13pt; line-height: 115%;"> The road to freedom is not strewn
with roses. It is a path covered with thorns, but at the end of it, there is
the full blown rose of liberty, awaiting the tired pilgrim. We have gained
freedom when we had paid the full price for our right to live. Freedom is to
live one’s life, with the window of the soul open to new thoughts, new ideas,
new aspirations. In 1947, Winston Churchill laughed at the idea of India as a
Democracy. Today, it is the world’s largest</span><span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;">‼</span></div>
<div align="center" class="MsoNormal" style="color: #999999; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;"></span></i></div>
<a name='more'></a><br />
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i><span style="font-size: 13pt; line-height: 115%;">“As we celebrate our
success, we must know</span></i></div>
<span style="color: orange;">
</span><br />
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">That it has not reached
its zenith, our story must grow.</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">We have come a long way
but there are fears</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">Though my lips have
smiles, still it appears,</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">Many eyes are
moist…many filled with tears.”</span></i></div>
<div class="MsoNormal" style="color: #444444;">
<span style="font-size: 13pt; line-height: 115%;">Even as we complete the 63rd<sup></sup> year of India becoming a republic, we still talk
about our rights, but refrain from uttering a word about our duties. Instead of
asking what the nation has done for you, you must first question yourself- What
have I done for my nation? For thousands of years, India has produced a
remarkable number of great leaders. We have a billion people to follow their
footsteps. <i style="mso-bidi-font-style: normal;">Now, we need one to step into
their shoes</i>. The health of democratic society may be measured by the
quality of functions performed by the private citizens. And also, we must speak
out of our duties first, and then demand for our rights. Too little freedom
brings stagnation, and too much brings chaos. Hence to lead an ideal life,
duties must be coined together with our rights. Our nation can continue its
march only if we all offer our hands and uplift the country. <i style="mso-bidi-font-style: normal;">I can disapprove of what you say, but I will
defend to death, your right to say it</i>. This is the essence of freedom. One
must be more aware and vigilant about his duties, than his rights.</span></div>
<div class="MsoNormal" style="color: #444444;">
<span style="font-size: 13pt; line-height: 115%;">So, let us
redeem our pledge that we would rather die on our feet, than live on our knees.</span></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">“Who dwells in our
memory with his spinning wheel?</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">Who reminds us
constantly and makes his appeal?</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">To redeem our pledge,
on this day let us ensure,</span></i></div>
<div align="center" class="MsoNormal" style="color: orange; text-align: center;">
<i style="mso-bidi-font-style: normal;"><span style="font-size: 13pt; line-height: 115%;">That our caravan not
falter on any score</span></i></div>
<div align="center" class="MsoNormal" style="color: #999999; text-align: center;">
<i style="color: orange;"><span style="font-size: 13pt; line-height: 115%;">Oh travelers, we must
yet, travel some more</span></i><i style="color: orange;"><span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;">‼”</span></i><span style="font-size: 13pt; line-height: 115%;"></span></div>
<div class="MsoNormal" style="color: #444444;">
<span style="font-size: 13pt; line-height: 115%;">Jaya
Hey…Jaya Hey…Jaya Hey</span><span style="font-family: Arial, sans-serif; font-size: 13pt; line-height: 115%;">!!</span><span style="font-size: 13pt; line-height: 115%;"> </span></div>
<div class="MsoNormal" style="color: #999999;">
<br /></div>
<div class="MsoNormal" style="color: #999999;">
<br /></div>
<div align="right" class="MsoNormal" style="color: #999999; text-align: right;">
<b><span style="font-size: 13pt; line-height: 115%;">-<span style="color: red;">Ajinkya Mandhare</span>.</span></b></div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com1tag:blogger.com,1999:blog-5359953784757764379.post-22320672145019560682012-01-23T12:17:00.000+05:302014-07-22T20:48:02.128+05:30Computer Engineering SEM VIII Question Papers<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #999999;">You can download the question papers from the download box present on my blog. Optionally, you can download it from the link</span> <a href="http://www.box.com/s/on7t95a34zqklms3hzmx" style="color: orange;">COMP_ENGG_SEM_VIII</a><span style="color: orange;"> </span></div>
<br />
<div>
You can
<a href="http://ajinkyamandhare.blogspot.in/p/contact-me.html" rel="author">Contact Me</a> for further assistance.
</div>Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com1tag:blogger.com,1999:blog-5359953784757764379.post-10433346398545553392012-01-21T19:45:00.000+05:302013-05-03T20:31:03.381+05:30C# code for connecting to a Web Page & Obtaining its Source Code/ Web Crawler Algorithm in C#<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="color: #444444;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Verdana, sans-serif;">HTTP is the primary mechanism for communicating with resources over the Web. It is a Stateless protocol, used for simple Request-Response communication. A developer may often want to obtain web pages & their source codes, for different reasons like: building a spider, obtaining info on a particular page, etc. For this purpose, the .NET Framework includes classes that aid in this respect.</span></div>
<b style="text-align: -webkit-auto;"><span style="color: orange; font-family: Verdana, sans-serif;"><br /></span></b>
<b style="text-align: -webkit-auto;"><span style="color: orange; font-family: Verdana, sans-serif;">Requesting & Obtaining an HTTP page:</span></b><br />
<span style="font-family: Verdana, sans-serif;"></span><br />
<a name='more'></a><span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div style="color: #444444;">
<span style="font-family: Verdana, sans-serif;">To obtain the HTTP page, we first need to establish a connection to it, & then obtain the page.</span></div>
<div style="text-align: left;">
<span style="font-family: Verdana, sans-serif;"><span style="color: #999999;"><span style="color: #444444;">For this purpose, C# provides two functions viz.</span> </span><b><span style="color: orange;">HttpWebRequest</span></b><span style="color: #999999;"> <span style="color: #444444;">& </span></span><b><span style="color: orange;">HttpWebResponse</span></b><span style="color: #999999;">.</span></span></div>
<div style="color: #444444; text-align: left;">
<span style="font-family: Verdana, sans-serif;">This involves specifying a web page to get, with a <i style="text-align: -webkit-auto;">HTTPWebRequest</i> object, which performs the actual request, and then using a <i style="text-align: -webkit-auto;">HTTPWebResponse</i> object to receive the page.
</span></div>
<div style="color: #444444; text-align: left;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="color: #444444; text-align: left;">
<span style="font-family: Verdana, sans-serif;">After this, the normal String methods can be used to obtain the source code of the web page and then, a number of manipulations can be made, as necessary!</span></div>
<div style="color: #444444; text-align: left;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: left;">
<div style="color: #444444;">
<span style="font-family: Verdana, sans-serif;">The C# code snippet for connecting to a web page & obtaining its source code is:</span></div>
<span style="color: #999999; font-family: Verdana, sans-serif;"><br /></span></div>
<span style="font-family: Verdana, sans-serif;"> </span><b style="font-family: Verdana, sans-serif; text-align: -webkit-auto;"><span style="color: red;">HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);</span></b><br />
<div style="text-align: -webkit-auto;">
<b><span style="color: red; font-family: Verdana, sans-serif;"> </span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: red; font-family: Verdana, sans-serif;"> HttpWebResponse resp = (HttpWebResponse)req.GetResponse();</span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: red; font-family: Verdana, sans-serif;"> </span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: red; font-family: Verdana, sans-serif;"> Stream istrm = resp.GetResponseStream();</span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: red; font-family: Verdana, sans-serif;"> </span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: red; font-family: Verdana, sans-serif;"> StreamReader rdr = new StreamReader(istrm);</span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: red; font-family: Verdana, sans-serif;"> </span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: red; font-family: Verdana, sans-serif;"> str = rdr.ReadToEnd();</span></b></div>
<div style="text-align: -webkit-auto;">
<span style="font-family: Verdana, sans-serif;"> </span></div>
<div style="color: #444444;">
<span style="font-family: Verdana, sans-serif;">The entire source code of the Web page under consideration is now stored in 'str'. </span></div>
<div style="color: #444444;">
<span style="font-family: Verdana, sans-serif;">Once we have the source code, we can define a number of functions, to manipulate the source code, in order to obtain the necessary information like: url in case of a crawler or spider!!</span></div>
<div style="color: #444444;">
<span style="font-family: Verdana, sans-serif;">This process of obtaining the urls from the source code, once we have 'str' is child's play, & hence it is left to you!! Still, if you have problem, here is the algo:</span></div>
<div style="text-align: -webkit-auto;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: orange; font-family: Verdana, sans-serif;">Step 1: Find Index Of ("href=\"http") from the start location & store it in 'i' (temp variable) </span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: orange; font-family: Verdana, sans-serif;">Step 2: Find index ' " ' from 'i' & add 1 to it & store it in 's' (temp variable)</span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: orange; font-family: Verdana, sans-serif;">Step 3: Find index of ' " ' from 's' & store it in 'e' (temp variable)</span></b></div>
<div style="text-align: -webkit-auto;">
<b><span style="color: orange; font-family: Verdana, sans-serif;">Step 4: Now obtain the substring from 's' to 'e-s' & store i in url(string variable)</span></b></div>
<div style="text-align: -webkit-auto;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="color: #444444;">
<span style="font-family: Verdana, sans-serif;">Now you can easily use this code & build your own simple crawler in C#!!</span></div>
<br />
<div>
You can
<a href="http://ajinkyamandhare.blogspot.in/p/contact-me.html" rel="author">Contact Me</a> for further assistance.
</div>
</div>
Ajinkya Mandharehttp://www.blogger.com/profile/10381020582269193461noreply@blogger.com1