• Home
  • About
  • Job Profile
  • Portfolio
  • Training
Blue Orange Green Pink Purple

RESTful API – The HTTPish …

Many newer application programmers are realizing the need to open their core functionality to a greater audience. Providing easy, unfettered access to your core API can help get your platform accepted, and allows for mashups and easy integration with other systems. → REST is the underlying architectural principle of the web and depends on HTTP […]

Read More 0 Comments   |   Posted by lazyboy
Apr 17

WordPress ‘Featured Image’, how to use…

WordPress stands for most common and popular CMS now a days. Sometimes we need just a media field for a image to be added in a post. WordPress latest 3+ version has this facility, so you don’t need to use any ‘custom field type’.

In default theme, this feature enabled by default, but when you are using a custom made theme or a theme of your choice which you downloaded, but not supported ‘featured Image’ section, then what to do.

Its very simple for wp developer to add that support to your theme. Add below code to your theme’s functions.php file :

add_theme_support('post-thumbnails');

Now you will see that section in your admin sidebar when adding/editing any page/post. And also you will find option at your ‘Screen Options’ section as below, so from there you can enable/disable that for future need.

In right sidebar, ‘Featured Image’ section after adding a image:

Now, You knew how to add theme support and how to add an image on admin panel. So to show this image on front-end, in any single post/page or in any loop, just add below code to show it between wp post loop:

<?php the_post_thumbnail();?>

This will show that image as you added in admin panel with that image ratio. Note that this code will execute when you are using wordpress’s default loop code like <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> and <?php endwhile; ?>

If you use custom loop code using other function like get_posts() or custom query like $wpdb->get_results(), then it depends on that way and you have to pull data with correspondence format.

Use, modify and share your thoughts and happy blogging :)

Read More 2 Comments   |   Posted by lazyboy
Apr 11

Add Page Excerpt Option in WordPress Admin Panel

WordPress is not a blogging platform now, has many other features, options, resources, plugins to fulfill your requirements.

In some wp version(like 3.1), for ‘pages’, no ‘excerpt’ option, even not option in ‘Screen Options’ to display it . So an easy way to add this to your wp admin panel, follow below steps:

add the following code to your functions.php file.

 //Add Excerpts to Pages 
function themeprefix_add_page_excerpt_support() {
 add_post_type_support( 'page', 'excerpt' ); 
} 
add_action('init', 'themeprefix_add_page_excerpt_support');

We have done this excerpt option by a wordpress hook. At first we used add_post_type_support function to use a specific post type option then we packed within a function. And this function called by a worpress hook/filter to make it available for admin panel.

Functions.php is found in “wp-content\themes\[your-currently-active-theme]\”.

Cheers :)

Read More 3 Comments   |   Posted by lazyboy
Apr 11

OpenCart config url,dir path problem and htaccess issue

Opencart is another easy, robust and handy e-commerce CMS. For beginner, there are some common problem related to URL, Directory path and .htaccess issues.

Following issues need to keep in mind during installation, moving to another server or installation on windows:

  • Use trailing slash after the url like define(‘HTTP_SERVER’, ‘localhost/myproject/’) otherwise it may not load all css, images and js files.
  • For windows, use path like define(‘DIR_APPLICATION’, ‘F:\wamp\www\myproject/catalog/’); as well as for other settings. It may be ok in normal way like define(‘DIR_APPLICATION’, ‘F:/wamp/www/myproject/admin/’);
  • For htaccess, if your store/project is in your document root which is generally public_html on cpanel servers that is ok for for default RewriteBase, but if it’s in a subfolder you will need to edit the file and change the ‘RewriteBase /’ to ‘RewriteBase /subfoldername/’

That’s all for some common issue. Have fun with open source opencart :)

Read More 0 Comments   |   Posted by lazyboy
Apr 11

isset() use techniques in php

isset

isset() is the most commonly used php construct as well as a good friend of a programmer. we frequently use it to check whether a variable has been set or not. it returns true if the variable has been set otherwise false… also return false if the variable has been set to null.

isset() is the only one of the three language constructs that accepts an arbitrary amount of parameters. Its accurate prototype is as follows:

<?php
isset($var1, $var2, $var3, ...);
?>

It only returns true, if all the variables have been defined; otherwise, it returns false. This is useful when you want to check if the required input variables for your script have really been sent by the client, saving you a series of single isset() checks.

So writing it with arbitrary parameters can be interesting upon your need! cheers!

Read More 0 Comments   |   Posted by lazyboy
Apr 07

Interview question set for a advanced PHP Programmer

Recently, I got a chance to face some questions which make sense for a PHP Programmer, who can rethink all about web development what he has been learned yet. I thought i can share those among yourselves just for sharing that what could be the questions for a advanced PHP Programmer.

Questions are as follows. I will try to give answers here and discussion about these time to time. Looking forward to hear from you guys about any question listed below.

  • Question: You are committing a file with bug fixes to the SVN, there is an issue with a conflict in the file what does this mean? How do you solve it?
  • Question: How would you find out what files were out of date within SVN and commit those specific files into a revision with a log message via the command line?
  • Question: How do you use memcached to optimize mysql queries?
  • Question: How do you iterate an array in smarty?
  • Question: PHP errors are not displaying on the page you are developing. You only have SFTP Access to change files. How do you display the errors?
  • Question: What is better and more efficient in development time for a large scale enterprise PHP / MySQL application. Using packages and open source classes or developing your own solutions?
  • Question: What are the risks of using user inputted data in SQL queries and how to eliminate this risk ?
  • Question: You have been given a specification and been briefed on a project. The specification included work that was already completed for the project but there are many bugs and you did not write this code. What do you do?
  • Question: There is a bug in your code, what do you do?
  • Question: Recently users are complaining they are being logged out of the site. The site uses sessions and php. Also recently a new webserver was added, bringing the total to 2. What could be causing this and how would it be solved?
  • Question: You need to create a search function for a website with over 30.000 searches per hour on a record set of 1.000.000 text records. How would you do this using MySQL?
  • Question: You need to integrate an external website’s data that does not have a API – describe this process.
  • Question: You’ve written a news service in PHP that needs to used by many external websites. How would you allow those websites to use your functions to display the news on their site ?
  • Question: You want to create an AJAX suggestion box that displays in real time suggestions related to the content of the search textfield. Describe how this process would work.

I think, some questions are really good and every PHP Programmer should know about those terms.

Read More 3 Comments   |   Posted by lazyboy
Apr 05

Javascript calculation…..

Guys, good day!

After a long time, started blogging again! today wanna discuss 1 important JS issue which we need in our daily development lot of times. When we need to calculate some values like a height of a div and add some extra px to that height, in such a situation we may add a digit with a variable. Sometimes its returns not expected value, its recommended to use ‘ParseInt‘ function to manipulate its correctly.

See below example :

var old_height = $('.mydiv').height();
var new_height = parseInt(old_height+10);

Now new_height has calculated value. we forget the use of this JS function and try to find out the errors, but this simple function needs to be remember in all case of addition.

Its just like a remember for experienced guys and a better practice info for beginner!

Cheers and have good practice!

 

Read More 0 Comments   |   Posted by lazyboy
Apr 05

Magento Admin Panel Login Problem

Magento! : ECOMMERCE PLATFORM FOR GROWTH …. recent days, Magento became most popular CMS for ecommerce.Recently when i started work with magento, fallen in problem regarding login to admin panel.

There are several issues to consider :

  • Using 127.0.0.1 in place of localhost for your base url when going to setup in localhost.
  • Best way is using IP, like your PC IP address or default 127.0.0.1.
  • Use 127.0.0.1 instead of localhost while db configuration in installation (may fix the problem)
  • For cookie related issue, please properly enable your browser cookie settings.
  • Finally check out for both ‘mod rewrite option’ and ‘base url validation option’ during installation.

** Recently I got another useful solution during installation of magento in another PC. The solution is to modify the core Magento code.

> Open app/code/core/Mage/Core/Model/Session/Abstract/Varien.php.

> Comment out the lines 80 to 83. The line number may vary in different magento version. But these lines exist near to line 80. You need to comment the comma (,) in line:: $this->getCookie()->getPath()//,

For Magento 1.4 or greater than 1.4 :

you have to comment code from line 86 to 98 in app/code/core/Mage/Core/Model/Session/Abstract/Varien.php. Like this:-

This may be helpful for beginners who are gonna to start magento.

Cheers!

Read More 1 Comment   |   Posted by lazyboy
Apr 05

Simple PHP Security in CodeIgniter

As web is now the part of our life and we can’t think our daily works without www. For both users and developers, security is a key question. I would like to share some simple security points in this post, which are common.

  • Cross Site Scripting(or XSS) is one of the most common application-layer web attacks. XSS commonly targets scripts embedded in a page which are executed on the client-side (in the user’s web browser) rather than on the server-side. An example of XSS may be as from user input. Suppose you put <textarea> on your site to get user input. But malicious user give input like this :
<script type="text/javascript">
window.locaton('http://example.com');
</script>

or it may be a unwanted alert message in javascript, which is not expected.So you definitely want to prevent this type of attack. I’m going to show the solution here in CodeIgniter. CodeIgniter has its built in input class.The example is below:

$data= $this->input->post('UserInput');
$data_xss = $this->input->xss_clean($data);

At first, you get user input by post method and now just pass that value to the function. if you print the final value, you will see the javascript code will be replaced by others like [removed].Now you can pass the value to database query or do anything with that value.

  • Use htmlentities( ) for user input . It will convert all applicable characters to HTML entities like below.
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

Some useful links for best practices and security:

  • http://bit.ly/5W1yoi
  • http://bit.ly/c3KxsL
  • http://bit.ly/7I4A

Cheers and practice with best approach. :)

Read More 0 Comments   |   Posted by lazyboy
Apr 05

Execute PHP code within a html/htm file

When a web page is call, the server checks two thongs, whether it is a html/htm file or a php/asp(etc) file. The key point is file extension or file type.If it is a normal .html/.htm file, server sends it direct to the browser. And if it is a php/asp(etc), server than execute the appropriate code before sending it to the browser.

Come to the point: Now you need to add some php code within your existing html file,then what is the process?
There are two ways, what i ever know and want to share with you,
1.Rename the html file to php file (the easiest way),
2.Using .htaccess file to allow php within html file.

if you follow the first one, it’s easy. but you may have incoming links or search engine ranking or if u change the file type, you need to change many code within your application.so in this situation, come to the second solution. ;)

The way is:
You need to add some command in your .htaccess file like below:
For html file :
AddType application/x-httpd-php .html

Or for .htm
AddType application/x-httpd-php .htm

If you only plan on including the PHP on one page, it is better to setup this way:
<Files myhome.html> AddType application/x-httpd-php .html </Files>

Example:
Now you can put php script like below in your html file :

<p id='php_cont'><?php echo "hi all"; ?></p>

N.B. Always be careful about your .htaccess file. if you have already one, just add the above command to the file, don’t replace all. and for beginner, the .htaccess file will be in your root folder, where your application or project exists (i.e. http://localhost/myapp)

That’s all. For very beginners it may be helpful and i think this is a common question for them that ‘How to use php in html file?’. cheers ;)

Read More 0 Comments   |   Posted by lazyboy
Apr 05

Go to a URL/link from drop down list/menu in html+javascript

In many web application, we see some kind of drop down list to go to a URL only by clicking on the list item, no need to click on any button. For the users, this is a nice experience that they don’t have to click on submit button.
I have described here in details the tutorial especially for beginners. Let we have a form like below:

<form method="post" action="http://www.example.com/submit.php">
<input type="submit" name="submit_button" value="Go">
<select name="url_list" >
<option value="http://www.example.com/index.html">list 1</option>
<option value="http://www.example.com/about.html">list 2</option>
</select>
</form>

we can improve the form performance by combining it with a simple javascript and it has below advantages:

1.It makes your page more efficient, because if JavaScript is enabled, the web browser can jump to the destination webpage itself without having to run the script. Also it is nicer for users because they do not need to select the “go” button.

2.The form will also continue to work with web browsers that do not have JavaScript available.

Now, the following example displays a drop down list with a js function. Include the js in your <head></head> of the file :

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin gotosite
function gotosite()
{
var URL = document.gotoform.url_list.options[document.gotoform.url_list.selectedIndex].value; window.location.href = URL;
}
// End gotosite -->
</script>

and now try the form like this :

<form name="gotoform" method="post" action="http://www.example.com/submit.php">
<noscript>
<!-- use noscript to only show this if no javascript is available -->
<input type="submit" name="submit_button" value="Go">
</noscript>
<select name="url_list" size="1" onChange="gotosite()">
<-- Value of first option is default, usually current page -->
<option value="http://www.example.com/submit.php"> Select a Site...</option>
<option value="http://www.example.com/index.html">list 1</option>
<option value="http://www.example.com/about.html">list 2</option>
</select>
</form>

we call ‘gotosite()’ function on ‘onChange’ of <select>, and this will help to jump to the url for each list.
Hope this will help the beginners for more reliable user experience.

Read More 1 Comment   |   Posted by lazyboy
Previous Page 2 of 3 Next Page

Saif The Green

  • View Saif's profile on LinkedIn
  • Recent Posts
    • RESTful API – The HTTPish …
    • SUSE – another user-friendly desktop Linux distributions
    • SEO meta techniques for a wordpress blog
    • Set favicon in cross browser and more…
    • WordPress custom URL rewrites and tips
  • Archives
    • October 2016
    • August 2016
    • August 2014
    • July 2014
    • April 2014
    • June 2013
    • April 2013
    • March 2013
  • Categories
    • CodeIgniter
    • Javascript
    • Linux
    • MySQL
    • opencart
    • php
    • SEO
    • Software Development
    • Web Development
    • Web Services
    • Wordpress
  • Meta
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Archives
    • October 2016
    • August 2016
    • August 2014
    • July 2014
    • April 2014
    • June 2013
    • April 2013
    • March 2013
  • Search







Saif The Green is proudly powered by WordPress
Entries (RSS) and Comments (RSS).