Top Questions:

  • 3 years-4 months

    Split time interval in 15 min slot

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    split time interval in 15 min slot using php

    $array_of_time = array ();
    $start_time    = strtotime ("2013-08-28 17:45:00");
    $end_time      = strtotime ("2013-08-28 22:15:00");
    
    $fifteen_mins  = 15 * 60;
    
    while ($start_time <= $end_time)
    {
       $array_of_time[] = date ("Y-m-d H:i:s", $start_time);
       $start_time  = $fifteen_mins;
    }
    
    print_r ($array_of_time);
     
  • 3 years-4 months

    Drag Drop multiple divs

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    you can drag drop all data between multiple divs

     <div id="1" dvSource dvSourceul">
    <ul id="dropul_1">
          <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" /> </li>
    </ul>
        </div>
    <div id="2">
    <ul id="dropul_2">
          <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" /> </li>
    </ul>
        </div>
    /********Jquery*********
    <script>
     $(function () {
                $("li.drop").draggable({
                    revert: "invalid",
                    refreshPositions: true,
                    drag: function (event, ui) {
                        ui.helper.addClass("draggable");
                       
                    },
                    stop: function (event, ui) {
                        if ($.ui.ddmanager.drop(ui.helper.data("draggable"), event)) {
                             ui.helper.removeClass("ui-draggable-dragging");
                             ui.helper.removeClass("draggable");
                        }
                        else {
                            //alert(" not dropped.");
                        }
                    }
                });
                $(".dvSourceul").droppable({
                    drop: function (event, ui ) {
                      var newId=event.target.id;
                      var aworkid=ui.draggable.attr('data-id');
                        ui.draggable.addClass("dropped");
                        $("#dropul_" newId).append(ui.draggable);
                        $.ajax({
                          type: "POST",
                          url: "update_work.php",
                          data:'id=' aworkid '&wrkid=' newId,
                          success: function(data){
                          // alert(data);
                          }
                          });
                    }
                });
            });
    
    </script>
  • 5 years-11 months

    Warning: Cannot modify header information - headers already sent by ERROR

    • Category : php
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    fix “Headers already sent” error in PHP

    The very quick fix for your problem will be to add

    ob_start();
    as the very first thing in your script if you only need it in this one script. If you need it in all your scripts add it as the very first thing in your header.php file.
  • 3 years-4 months

    Image Compress

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    COmpress your image size using php

    <?php
     $name = ''; $type = ''; $size = ''; $error = '';
      function compress_image($source_url, $destination_url, $quality) {
    
        $info = getimagesize($source_url);
    
            if ($info['mime'] == 'image/jpeg')
                  $image = imagecreatefromjpeg($source_url);
    
            elseif ($info['mime'] == 'image/gif')
                 $image = imagecreatefromgif($source_url);
    
           elseif ($info['mime'] == 'image/png')
                 $image = imagecreatefrompng($source_url);
    
           imagejpeg($image, $destination_url, $quality);
        return $destination_url;
      }
    
     if ($_POST) {
    
           if ($_FILES["file"]["error"] > 0) {
                  $error = $_FILES["file"]["error"];
            } 
            else if (($_FILES["file"]["type"] == "image/gif") || 
         ($_FILES["file"]["type"] == "image/jpeg") || 
         ($_FILES["file"]["type"] == "image/png") || 
          ($_FILES["file"]["type"] == "image/pjpeg")) {
    
                 $url = 'destination .jpg';
    
                  $filename = compress_image($_FILES["file"]["tmp_name"], $url, 80);
                  $buffer = file_get_contents($url);
    
                  /* Force download dialog... */
                  header("Content-Type: application/force-download");
                 header("Content-Type: application/octet-stream");
                 header("Content-Type: application/download");
    
         /* Don't allow caching... */
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
                  /* Set data type, size and filename */
                  header("Content-Type: application/octet-stream");
                 header("Content-Transfer-Encoding: binary");
                  header("Content-Length: " . strlen($buffer));
                 header("Content-Disposition: attachment; filename=$url");
    
                 /* Send our file... */
                  echo $buffer;
           }else {
                 $error = "Uploaded image should be jpg or gif or png";
            }
     }
    ?>
    <html>
          <head>
                <title>Php code compress the image</title>
          </head>
         <body>
    
        <div class="message">
                         <?php
                            if($_POST){
                               if ($error) {
                                   ?>
                                   <label class="error"><?php echo $error; ?></label>
                            <?php
                                    }
                             }
                         ?>
                     </div>
        <fieldset class="well">
                       <legend>Upload Image:</legend>                
          <form action="" name="myform" id="myform" method="post" enctype="multipart/form-data">
            <ul>
                        <li>
                <label>Upload:</label>
                                          <input type="file" name="file" id="file"/>
              </li>
             <li>
                <input type="submit" name="submit" id="submit" class="submit btn-success"/>
             </li>
           </ul>
         </form>
       </fieldset>
     </body>
    </html>
     
  • 3 years-4 months

    Drag drop

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Drag Drop your table's data using jQuery,Ajax,php and mysql

    /**********HTML PART START**************/
    
    <div class="x_content my-data" id="">
    
                      <table class="table table-bordered">
                        <thead>
                          <tr>
                            <th>#</th>
                            <th>Image</th>
                            <th>Category</th>
                            <th>Edit</th>
                            <th>Delete</th>
                          </tr>
                        </thead>
    <?php
      
      $query = "SELECT * FROM product ORDER BY pos ASC";
      $result = mysql_query($query) or die(mysql_error().': '.$query);
      if(mysql_num_rows($result)) {
    ?>
    <form id="dd-form" action="" method="post">
      <input type="checkbox" value="1" name="autoSubmit" id="autoSubmit" class="autoooo" checked/>
    <tbody id="sortable-list">
      <?php 
        $order = array();
        $i=1;
        while($row = mysql_fetch_assoc($result)) {
            $img=explode(",",$row['product_img']);
                           $img=explode(",",$row['product_img']);
    $catqry=mysql_fetch_array(mysql_query("select * from category where id='".$row['product_cat_id']."'"));
    $scatqry=mysql_fetch_array(mysql_query("select * from subcategory where id='".$row['product_subcat_id']."'"));
    
                           echo '<tr title="',$row['id'],'"><td>',$i,'</td><td><img src="',$img[0],'" height="50" width="50"></td><td>',$catqry['cat_name_eng'].'/'.$catqry['cat_name_china'],'</td><td><a href="?edit=',$row['id'],'"><i class="fa fa-pencil"></i></a></td><td><a href="?delete=',$row['id'],'" onclick="return confirm("Are you sure you want to delete")"><i class="fa fa-trash"></i></a></td></tr>';
          $order[] = $row['id'];
          $i  ;
        }
      ?>
    </tbody>
    <br />
    <input type="hidden" name="sort_order" id="sort_order" value="<?php echo implode(',',$order); ?>" />
    </form>
    <?php } ?>
    
    
                      </table>
    
                    </div>
                  </div>
            
            </div>
    <style type="text/css" media="screen">
    #sortable-list1   { padding:0; }
    #sortable-list1 tr  { padding:4px 8px; color:#000; cursor:move; list-style:none; width:100px; background:#ddd; margin:10px 0; border:1px solid #999; }
    #sortable-list1 tr td { text-align: center; }
    #message-box1   { padding:4px 8px; margin:0 0 14px 0; width:500px; }
    .autoooo{ display : none; }
    </style>
    /**********HTML PART END**************/
    /**********SCRIPT PART START**************/
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
      <script>
    /* when the DOM is ready */
    $(document).ready(function() {
    
      /* grab important elements */
      var sortInput = $('#sort_order');
      var submit = $('#autoSubmit');
      var messageBox = $('#message-box');
      var list = $('#sortable-list');
      /* create requesting function to avoid duplicate code */
      var request = function() {
      $.ajax({
      url: "drop_ajax.php",
      data:'sort_order='   sortInput[0].value   '&ajax='   submit[0].checked   '&do_submit=1&byajax=1',
      type: "POST",
      success: function(data) {
            window.location.reload();
      }
      });
      };
      /* worker function */
      var fnSubmit = function(save) {
       
        var sortOrder = [];
        list.children('tr').each(function(e){
          sortOrder.push($(this).data('id'));
        });
        sortInput.val(sortOrder.join(','));
       // console.log(sortInput.val());
        if(save) {
          request();
        }
      };
      /* store values */
      list.children('tr').each(function(e) {
        var tr = $(this);
        tr.data('id',tr.attr('title')).attr('title','');
      });
      /* sortables */
      list.sortable({
        opacity: 0.7,
        update: function() {
          fnSubmit(true);
        }
      });
      list.disableSelection();
    });
    </script>
    /**********SCRIPT PART END**************/
    /**********AJAX PART START**************/
    <?php
    include('config.php'); /include your db file here
    /* on form submission */
    if(isset($_POST['do_submit']))  {
      /* split the value of the sortation */
      $ids = explode(',',$_POST['sort_order']);
     /* run the update query for each id */
      foreach($ids as $index=>$id) {
       $id = (int) $id;
        if($id != '') {
         $query = 'UPDATE product SET pos = '.($index   1).' WHERE id = '.$id;
         $result = mysql_query($query) or die(mysql_error().': '.$query);
        }
     }
     
      /* now what? */
     if($_POST['byajax']) { die(); } else { $message = 'Sortation has been saved.'; 
     
      echo $message;
      }
    }
    ?>
    
    
    /**********AJAX PART END**************/
  • 3 years-4 months

    Share with Whatsapp

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    share on whatsapp using php

    <a data-text="Your message goes here.." data-link="http://dorcode.com" class="btn btn-sucess">Share</a>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript">
    
    jQuery(document).ready(function() {
    
    var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
        }
    };
    jQuery(document).on("click", '.whatsapp', function() {
            if( isMobile.any() ) {
    
                var text = jQuery(this).attr("data-text");
                var url = jQuery(this).attr("data-link");
                var message = encodeURIComponent(text)   " - "   encodeURIComponent(url);
                var whatsapp_url = "whatsapp://send?text="   message;
                window.location.href = whatsapp_url;
            } else {
                alert("Please share on mobile device");
            }
    
        });
    });
    </script>
     
  • 5 years-11 months

    Generating cryptographically secure tokens in php

    • Category : php
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    In order to generate token for access to api and other

    Here is the correct solution:
    $token = bin2hex(openssl_random_pseudo_bytes(16));
     
  • 3 years-4 months

    htaccess code for increase website speed

    • Category : htaccess
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    increase your site speed by adding this code

    <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>
    # END gzip file compression
    
    FileETag none
    
    # BEGIN gzip file compression
    # Compress HTML, CSS, JavaScript, Text, XML and fonts
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/rss xml
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/xhtml xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE font/opentype
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE image/svg xml
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
    # Remove browser bugs
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    Header append Vary User-Agent
    
    <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
           ExpiresActive On
           ExpiresDefault "access plus 1 year"
    </FilesMatch>
    
    /********Add below code to header start of site**********/
    <?php ob_start('ob_gzhandler'); ?>
     
  • 3 years-4 months

    5 Star Rating Using php,ajax,jQuery

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    simple php rating in php

    <?php
    require "user/class.user.php";
    $auth_user = new USER();
    /********PDO Code***********/
    $email='user@gmail.com';
    $user=$auth_user->runQuery("SELECT * FROM login where email=:email");
    $user->execute(array(':email'=>$email));
    $userdatasingle=$user->fetchAll();
    $userdatasingle=$userdatasingle[0];
    ?>
    /*****HTML*******/
    <div class="rating">
                          
     <input type="hidden" name="rating" id="rating" value="<?php echo $userdatasingle["rating"]; ?>" />
           <ul onMouseOut="resetRating(<?php echo $userdatasingle["id"]; ?>);">
                 <?php
                 for($i=1;$i<=5;$i  ) {
                 $selected = "";
                 if(!empty($userdatasingle["rating"]) && $i<=$userdatasingle["rating"]) {
                 $selected = "selecteds";
                 }
         ?>
      <li class='<?php echo $selected; ?>' onmouseover="highlightStar(this,<?php echo $userdatasingle["id"]; ?>);" onmouseout="removeHighlight(<?php echo $userdatasingle["id"]; ?>);" onClick="addRating(this,<?php echo $userdatasingle["id"]; ?>);">&#9733;</li>  
                            <?php }  ?>
                        <ul>
                        <span class="ratings"><a href="#" class="Lgreen-txt font-6 rat-txt"><?php echo $userdatasingle["rating"]; ?> anmeldelser</a>
                       </span>
    </div> 
    /***********Script*************/
    <script>
    function highlightStar(obj,id) {
      removeHighlight(id);    
      $('.rating li').each(function(index) {
        $(this).addClass('highlights');
        if(index == $('.rating li').index(obj)) {
          return false; 
        }
      });
    }
    
    function removeHighlight(id) {
      $('.rating li').removeClass('selecteds');
      $('.rating li').removeClass('highlights');
    }
    
    function addRating(obj,id) {
      $('.rating li').each(function(index) {
        $(this).addClass('selecteds');
        $('#rating').val((index 1));
        if(index == $('.rating li').index(obj)) {
          return false; 
        }
      });
      $.ajax({
      url: "add_rating.php",
      data:'id=' id '&rate=' $('#rating').val(),
      type: "POST",
      success: function(data) {
      $(".rating").load(location.href " .rating>*","");
      }
      });
    }
    
    function resetRating(id) {
      if($('#rating').val() != 0) {
        $('.rating li').each(function(index) {
          $(this).addClass('selecteds');
          if((index 1) == $('#rating').val()) {
            return false; 
          }
        });
      }
    } 
    </script>
    /**********AJAX File*************/
    require "user/class.user.php";
    $auth_user = new USER();
    
    if (isset($_POST['rate']) && !empty($_POST['rate'])) {
     
        $rate = $_POST['rate'];
        $id = $_POST['id'];
    // check if user has already rated
        $sql = $auth_user->runQuery("UPDATE `login` SET rating=:rating WHERE `id`=:id");
       $sql->execute(array(':id'=>$id,':rating'=>$rate));
       
    }
     
  • 5 years-11 months

    Magento. Adding page links to the navigation bar

    • Category : magento
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    This tutorial shows how to add page links to Magento navigation bar. In order to add the page links to the navigation bar, you should perform the following steps:

    Step 1: Adding the Subcategory
     
    1. Go to Catalog -> Manage Categories in your Magento Admin.

    2. Select ‘Default Category’ on the left, then click the ‘Add Subcategory’ button:
    3. Fill in the fields:
    4. – Specify your link Name.
    5. – Set ‘Is Active’ to Yes.
    6. – In the URL Key field type the name of your page link in lowercase letters with hyphens instead of spaces (f.e.’About Us’ becomes about-us):
    7. – Scroll down to the bottom of the form and set Include to Navigation Menu to ‘yes’.
    8. – Click ‘Save Category’ button:
     

    Step 2: Creating a Redirect
     

    1. Navigate to Catalog -> URL Rewrite Management.
    2. In the search box of the Request Path column, type in the URL key for the subcategory, and click Search.
    3. When the subcategory is located, click ‘Edit’ to open the record:
    4. NOTE: you will have records for each installed language. You can open the record for each language in the new browser tab.
    5. Open the notepad on your PC and save the following info: the ID path of your URL Rewrite and the Request path:
    6. Now we should delete the URL Rewrite for each language – click the Delete button at the top right.

    Step 3: Adding a new URL rewrite
     
    1. In Catalog -> URL Rewrite Management click Add URL Rewrite button at the top right.

    2. In the Create URL Rewrite field select ‘Custom’.

    3. Fill in the URL Rewrite Information form:

      – Add the ID path for the item which you have noted and saved in the notepad on step 2.2.

      – Add the Request Path for the item which you have noted and saved in the notepad on step 2.2.

      – To fill in the Target Path field, open any navigation menu on your site and copy-paste its url into the field, f.e: http://yourdomain.com/index.php/contacts/ (where ‘contacts’ is the Request Path for the Contact Us navigation page). Replace the Request Path with the new item Request Path which you have noted and saved in the notepad on step 2.2 of this tutorial.

    4. Set Redirect to ‘Permanent 301′.

    5. Click ‘save’ button at the top right:
       

    Step 4: Creating a page
     
    1. Go to CMS -> Pages.

    2. Click ‘Add New Page’.

    3. Specify the page title, the URL key for the page, select All Store Views:

    4. Switch to the Content Tab on the left. Put the html for your page content here.

    5. Switch to the Design Tab on the left. In the layout field choose the desired Page Layout:

    6. Click ‘Save Page’

    Step 5: Clearing your Magento Cache

    This is the end of the tutorial. You’ve learned how to add page links to Magento navigation bar