Top Questions

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jul 31, 2016

    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>
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Dec 23, 2015
    <form action="" method="post" enctype="multipart/form-data" class="upload_bus"> 
    div class="btn-group col-lg-3 col-md-3 col-sm-6 col-xs-12 rightgp-btns">
      <input class="create-doc" id="upbuss"  type="file" name="upbus" >
    </div>
    </form>
    <center><div id="loader-icon" style="display:none;"><img src="images/loader-time.gif" height="100px" width="100px" /></div></center>
    <script>
    $('input#upbill').change(function(){
    $('form.upload_b').submit();
    })
    $('form.upload_b').submit(function(e){
      var formData = new FormData(this);
      $('#loader-icon').show();
    $.ajax({
    url: "upload_file.php",            
    type: "POST",
    data:  formData,
    mimeType:"multipart/form-data",
    contentType: false,
    cache: false,
    processData:false,
    success: function(data)
    {
      $('#loader-icon').hide();
       window.location.href="example.php";
    }
    });
    return false;
    });
    </script>

     

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Sep 15, 2017

    Using this code you can upload and image using curl with third party role

    
       /*Send Page*/
    
       $filename = covertImage($filename);
       
       $fields = array(
                            'customer_name' => 'Gulshan Sharma',
                            'filename' => $filename,
    
                    );
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL,'http:example.com/upload/');
                    curl_setopt($ch, CURLOPT_POST, 1);
                    curl_setopt($ch, CURLOPT_USERAGENT, "webapp");
                    //curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
    
                    // in real life you should use something like:
                    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
                    // receive server response ...
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                    curl_setopt($ch, CURLOPT_USERPWD, "xxx:xxx"); 
                    $server_output = curl_exec ($ch);
                    curl_close ($ch);
    
      function covertImage($path){
    
                $type = pathinfo($path, PATHINFO_EXTENSION);
                $data = file_get_contents($path);
                $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
                return $base64;
       }
     /*RecivePage*/
    
       $filename = base64_to_jpeg($_POST['filename']);
       
       echo $filename;
       
       function base64_to_jpeg($base64_string) {
                         $upload_path = '/hosted-libraries/temp/';
                        $upload_path = $_SERVER['DOCUMENT_ROOT'] . $upload_path;
                        $newImg = uniqid();
                        $img = str_replace('data:image/png;base64,', '', $base64_string);
                        $img = str_replace(' ', ' ', $img);
                        $data = base64_decode($img);
                        $file = $upload_path . $newImg . '.png';
                        $success = file_put_contents($file, $data);
                        if($success)
                            return $file;
                        else
                            FALSE;
                       
         }
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Nov 19, 2016

    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);
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Mar 30, 2016

    You can generate refer code or random code using this code in php.its easy to implement and use.

    <?php
        $character_set_array = array();
        $character_set_array[] = array('count' => 6, 'characters' => 'abcdefghijklmnopqrstuvwxyz');
        $character_set_array[] = array('count' => 1, 'characters' => '0123456789');
        $character_set_array[] = array('count' => 1, 'characters' => '!@#$ -*&?:');
        $temp_array = array();
        foreach ($character_set_array as $character_set) {
            for ($i = 0; $i < $character_set['count']; $i   ) {
                $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];
            }
        }
        shuffle($temp_array);
        $refercode= implode('', $temp_array);
        echo $refercode;
        ?>
  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Aug 31, 2017

    Using this module you can hide requested parameters from inspect element

    var http = new XMLHttpRequest();
    var url = "Url Path";
    var params ='Your parameters';
    http.open("GET", url, true);
    
    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    
    http.onreadystatechange = function() {//Call a function when the state changes.
        if(http.readyState == 4 && http.status == 200) {
            console.log(http.responseText);
        }
    http.send(params);
    }
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jul 28, 2016

    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.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Sep 9, 2018

    Customer session does not work except some pages

    Method 1.  To check if customer is logged: (best way)Create helper file like Data.phphow to create custom helper or module https://www.dorcode.com/blog/52/how-to-create-and-use-helpers-in-magento-2


    <?php
    namespace Magento\Mytheme\Helper;
    
    class Data extends \Magento\Framework\App\Helper\AbstractHelper
    {
        protected $_customerSession;
        protected $_customerSessionn;
    
        public function __construct(\Magento\Framework\App\Helper\Context $context,
                \Magento\Framework\App\Request\Http $request,
                \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
                \Magento\Customer\Model\SessionFactory $customerSession,
                \Magento\Customer\Model\Session $customerSessionn
            ) 
        {
            $this->request = $request;
            $this->customerRepository = $customerRepository;
            $this->_customerSession = $customerSession;
            $this->_customerSessionn = $customerSessionn;
            parent::__construct($context);
        }
        public function getCustomerName(){
            $customer = $this->_customerSession->create();
            return $customer->getCustomer()->getName();
        }
        public function isLoggedIn()
        {
            return $this->_customerSessionn->isLoggedIn();
        }
    }
    ?>
    
    Call to your template :
    
    <?php
    $myhelper = $this->helper('Magento\Mytheme\Helper\Data');
    $cname=$myhelper->getCustomerName();
    $isLoggedIn=$myhelper->isLoggedIn();
    
    if ($isLoggedIn):
    	   echo 'login';
    else : 
    	  echo 'not login';
    endif;
    ?>
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Jan 10, 2017

    If the strings are different [iframe] and [/iframe], take a look at this. copy his code below:

    <?php
    function get_string_between($string, $start, $end){
        $string = ' ' . $string;
        $ini = strpos($string, $start);
        if ($ini == 0) return '';
        $ini  = strlen($start);
        $len = strpos($string, $end, $ini) - $ini;
        return substr($string, $ini, $len);
    }
    $string='testing [iframe]dorcode.com[/iframe] test';
    $parsed = get_string_between($string, '[iframe]', '[/iframe]');
    echo $parsed; // output: dorcode.com
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Jul 2, 2016

    When you’re using a sophisticated design, CSS files can quickly become very long, and takes time to load. I have compiled interresting ways of compressing CSS files by using PHP.

    (1.)
    <link rel="stylesheet" type="text/css" media="screen" href="/style.css.php"/>
    Once you successfully rename your css files, edit it and add the following code at the beginning of the file:
    <?php if(extension_loaded('zlib')){ob_start('ob_gzhandler');} header("Content-type: text/css"); ?>
     

    2 Answers

    View More