Sunday, November 17, 2013

How to get current page URL in Codeigniter?

For getting complete URL:

By using the current_url() method we can get the current page URl of the page.

Example:

$page_url=current_url();
echo $page_url;

For getting URI segments:

By using the following statement we can get the segments in the URI.

Syntax:

$this->uri->segment(n);
           where n=1 for controller
                     n=2 for method
                     n=3,4,5,6........ for parameters.
 
Example:

URL:   http://localhost/nareshphp/login/home

echo $this->uri->segment(1); //It will returns login as output

echo $this->uri->segment(2); //It will returns home as output


For getting current controller and method names:

$this->router->fetch_class(); //It will returns controller name

$this->router->fetch_method(); //It will return current method name.


Keep Smiling....

Tuesday, August 20, 2013

What is Mail Cron?

Mail Cron:
Mail Cron is a UNIX command used for sending mails to customers at time intervals through SMTP's.
Cron Syntax:
/usr/bin/GET  http://your site or mail sending area complete path
Example:
/usr/bin/GET  http://www.naresh-php.com/index.php/mail/send_mails/mails_list

Keep Smileing...

Monday, August 12, 2013

How to display clock using Javascript in PHP?

The following snippet of code display current time in your web page.

JavaScript
 <script  type="text/javascript" >
   function updateClock () {
    var currentTime = new Date();
    var month = currentTime.getMonth();
    var date = currentTime.getDate();
    var year = currentTime.getFullYear();
    var currentHours = currentTime.getHours ();
    var currentMinutes = currentTime.getMinutes ();
    var currentSeconds = currentTime.getSeconds ();
   
    var months = new Array(
    "January", "February", "March", "April",
    "May", "June", "July", "August", "September",
    "October", "November", "December");
   
    // Pad the minutes and seconds with leading zeros, if required
    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
   
    var currentTimeString = months[month]+" "+ date +", "+year+" "+currentHours + ":" + currentMinutes + ":" + currentSeconds;
   
    document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}
</script>

HTML Code
<body onload="updateClock(); setInterval('updateClock()', 1000 )">
<div id="clock" align="center" style="color:#F30; font-weight:100;">&nbsp;</div>
</body>


Have a nice day....

Simple captcha using jQuery in PHP?


PHP Code

$length = 6;
$captcha = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);


HTML Code

<input type="text" name="captcha" value="<?php echo $captcha; ?>"  id="captcha" />

Enter the code above here :

<input type="password" name="Enter Code" />

Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</td>


JS Code

<script>
function refreshCaptcha()
{
 var text = '';
    var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

    for(var i=0; i < 6; i++)
    {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    }
    $("#captcha").change().val(text);
}
</script>


Keep Smileing...

Friday, June 28, 2013

How to add menu to footere in wordpress?

The following single line code add in footer where you want to show menu bar.


Syantax:

<?php wp_nav_menu(array('menu' => 'name')); ?>
                          where name = Menu slug name.

Example:

<?php wp_nav_menu(array('menu' => 'my-custom-menu')); ?>

Wednesday, June 26, 2013

How to change Woocommerce products per page?

By adding the following one line code to your functions.php file, we will change the products per page in Woocommerce.
Now i would like to display 12 products in the place of regular 10 products.


add_filter('loop_shop_per_page',create_function('$cols','return 12;'),20);

Friday, June 21, 2013

Show cart contents / total at WooCommerce header in Wordpress?

Add the following bit of code to your header file exactly where you want to display the cart total items value.

<?php global $woocommerce; ?>
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?>
</a>

<!---Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)---->

<?php
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>

<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?>
</a>

<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
?>

Keep Smiling.
Naresh.