1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP view http headers scripts

Discussion in 'PHP' started by baotram, Feb 25, 2013.

  1. #1
    function.php
    
    <?
        function random_image($string)
        {
            $_SESSION['key']=$string;
            $im    = imagecreate(50,30);
            imagecolorallocate($im,255,255,255);
            $textcolor = imagecolorallocate($im, 0, 0, 255);
            imagestring($im,5,0, 0, $string, $textcolor);
            imagedestroy($im);
            
        }
          function assign_rand_value($num)
        {
            // accepts 1 - 36
              switch($num)
              {
                case "1":
                     $rand_value = "a";
                    break;
                case "2":
                    $rand_value = "b";
                    break;
                case "3":
                    $rand_value = "c";
                    break;
                case "4":
                    $rand_value = "d";
                    break;
                case "5":
                    $rand_value = "e";
                    break;
                case "6":
                    $rand_value = "f";
                    break;
                case "7":
                    $rand_value = "g";
                    break;
                case "8":
                    $rand_value = "h";
                    break;
                case "9":
                    $rand_value = "i";
                    break;
                case "10":
                    $rand_value = "j";
                    break;
                case "11":
                    $rand_value = "k";
                    break;
                case "12":
                    $rand_value = "l";
                    break;
                case "13":
                    $rand_value = "m";
                    break;
                case "14":
                    $rand_value = "n";
                    break;
                case "15":
                    $rand_value = "o";
                    break;
                case "16":
                    $rand_value = "p";
                    break;
                case "17":
                    $rand_value = "q";
                    break;
                case "18":
                    $rand_value = "r";
                    break;
                case "19":
                    $rand_value = "s";
                    break;
                case "20":
                    $rand_value = "t";
                    break;
                case "21":
                    $rand_value = "u";
                    break;
                case "22":
                    $rand_value = "v";
                    break;
                case "23":
                    $rand_value = "w";
                    break;
                case "24":
                     $rand_value = "x";
                    break;
                case "25":
                    $rand_value = "y";
                    break;
                case "26":
                     $rand_value = "z";
                    break;
                case "27":
                    $rand_value = "0";
                    break;
                case "28":
                    $rand_value = "1";
                    break;
                case "29":
                    $rand_value = "2";
                    break;
                case "30":
                    $rand_value = "3";
                    break;
                case "31":
                    $rand_value = "4";
                    break;
                case "32":
                    $rand_value = "5";
                    break;
                case "33":
                    $rand_value = "6";
                    break;
                case "34":
                    $rand_value = "7";
                    break;
                case "35":
                    $rand_value = "8";
                    break;
                case "36":
                    $rand_value = "9";
                    break;
              }
            return $rand_value;
        }
        function get_rand_numbers($length)
        {    
              if($length>0) 
              { 
                  $rand_id="";
                   for($i=1; $i<=$length; $i++)
                   {
                       mt_srand((double)microtime() * 1000000);
                       $num = mt_rand(1,36);
                       $rand_id .= assign_rand_value($num);
                   }
              }
            return $rand_id;
        } 
        function format_number($str)
            {
                return number_format($str, 2, '.', '');
            }
            function RTESafe($strText) 
            {
                //returns safe code for preloading in the RTE
                $tmpString = trim($strText);
                
                //convert all types of single quotes
                $tmpString = str_replace(chr(145), chr(39), $tmpString);
                $tmpString = str_replace(chr(146), chr(39), $tmpString);
                $tmpString = str_replace("'", "&#39;", $tmpString);
                
                //convert all types of double quotes
                $tmpString = str_replace(chr(147), chr(34), $tmpString);
                $tmpString = str_replace(chr(148), chr(34), $tmpString);
            //    $tmpString = str_replace("\"", "\"", $tmpString);
                
                //replace carriage returns & line feeds
                $tmpString = str_replace(chr(10), " ", $tmpString);
                $tmpString = str_replace(chr(13), " ", $tmpString);
                
                return $tmpString;
            }
            function redirect($to)
            {
                  $schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
                  $host = strlen($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME'];
                 //$temp_local = "mytravelasia";
                //echo "if url :".$schema."://".$host."/".$temp_local."/".$to;
            
                if (headers_sent()) 
                {
                    //$temp_local = "mytravelasia";
                    //echo "<br>if url :".$schema."://".$host."/".$temp_local."/".$to;
                
                    //echo "<br>In if :";
                    return false;
            
            
                }
                  else
                  {
                    header("HTTP/1.1 301 Moved Permanently");
                    // header("HTTP/1.1 302 Found");
                    // header("HTTP/1.1 303 See Other");
                    $temp_local = "stamford";
                    //echo "else url :".$schema."://".$host."/".$temp_local."/".$to;
                    header("Location: $schema://$host/$temp_local/$to");
                    exit();
                 }
        }
        function redirect1($to)
            {
                  $schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
                  $host = strlen($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME'];
                 //$temp_local = "mytravelasia";
                //echo "if url :".$schema."://".$host."/".$temp_local."/".$to;
            
                if (headers_sent()) 
                {
                    //$temp_local = "mytravelasia";
                    //echo "<br>if url :".$schema."://".$host."/".$temp_local."/".$to;
                
                    //echo "<br>In if :";
                    return false;
            
            
                }
                  else
                  {
                    header("HTTP/1.1 301 Moved Permanently");
                    // header("HTTP/1.1 302 Found");
                    // header("HTTP/1.1 303 See Other");
                    $temp_local = "mca";
                    //echo "else url :".$schema."://".$host."/".$temp_local."/".$to;
                    header("Location: $schema://$host/$temp_local/$to");
                    exit();
                 }
        }
        
        // Encrpting the Data
        function encrypt($id)
        {
            $eno = $id ;
            $eno = ($eno*3900)/13;
            $enew_no = dechex($eno);
            return $enew_no;
        }
    
        // Dycrypting the Data
        function decrypt($id)
        {
            $dno =  hexdec($id) ;
            $dno = ($dno*(13/3900));
            return $dno;
        }
        function to_month($id)
        {
            /*January
            February
            March
            April
            May
            June
            July
            August
            September
            October
            November
            December*/
            
            if($id==1)
                return "January";
            else if($id==2)
                return "February";
            else if($id==3)
                return "March";
            else if($id==4)
                return "April";
            else if($id==5)
                return "May";            
            else if($id==6)
                return "June";
            else if($id==7)
                return "July";
            else if($id==8)
                return "August";
            else if($id==9)
                return "September";
            else if($id==10)
                return "October";
            else if($id==11)
                return "November";
            else if($id==12)
                return "December";            
            
        }
        
        
        
        // Fuction to Replace " ' with space
        function replace($givenstr)
        {
            $str = $givenstr;
            $chr = array("'");
            $finalstr = str_replace($chr, "\'", $str);
            return $finalstr;
        }
        function replace_date($date_to)
        {
            $str = $date_to;
            $chr = array("-","/");
            $date_to = str_replace($chr, "*", $str);
            $exp_date = explode("*",$date_to);
            $date_to = $exp_date[2]."-".$exp_date[1]."-".$exp_date[0];
            return($date_to);
        }
        function replace_date1($date_to)
        {
            $str = $date_to;
            $chr = array("-","/");
            $date_to = str_replace($chr, "/", $str);
            $exp_date = explode("/",$date_to);
            return($exp_date);
        }
        
        function replace_comm($givenstr)
        {
            $str = $givenstr;
            $chr = array("'",",");
            $finalstr = str_replace($chr, "", $str);
            return $finalstr;
        }
        function replace_slash($givenstr)
        {
            $str = $givenstr;
            $chr = array("/");
            $finalstr = str_replace($chr, "_", $str);
            return strtolower($finalstr);
        }
        function add_slash($givenstr)
        {
            $str = $givenstr;
            $chr = array("_");
            $finalstr = str_replace($chr, "/", $str);
            return strtolower($finalstr);
        }
        function replace_safaricategory($givenstr)
        {
            $str = $givenstr;
            $chr = array("'"," ");
            $finalstr = str_replace($chr, "*", $str);
            return strtolower($finalstr);
        }
        function add_safaricategory($givenstr)
        {
            $str = $givenstr;
            $chr = array("*");
            $finalstr = str_replace($chr, " ", $str);
            return $finalstr;
        }
        
        function date_diff($interval, $datefrom, $dateto, $using_timestamps = false) 
        {
          /*
            $interval can be:
            yyyy - Number of full years
            q - Number of full quarters
            m - Number of full months
            y - Difference between day numbers
              (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
            d - Number of full days
            w - Number of full weekdays
            ww - Number of full weeks
            h - Number of full hours
            n - Number of full minutes
            s - Number of full seconds (default)
          */
         
         if (!$using_timestamps) {
            $datefrom = strtotime($datefrom, 0);
            $dateto = strtotime($dateto, 0);
          }
          $difference = $dateto - $datefrom; // Difference in seconds
           
          switch($interval) {
           
            case 'yyyy': // Number of full years
        
              $years_difference = floor($difference / 31536000);
              if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) {
                $years_difference--;
              }
              if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) {
                $years_difference++;
              }
              $datediff = $years_difference;
              break;
        
            case "q": // Number of full quarters
        
              $quarters_difference = floor($difference / 8035200);
              while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                $months_difference++;
              }
              $quarters_difference--;
              $datediff = $quarters_difference;
              break;
        
            case "m": // Number of full months
        
              $months_difference = floor($difference / 2678400);
              while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                $months_difference++;
              }
              $months_difference--;
              $datediff = $months_difference;
              break;
        
            case 'y': // Difference between day numbers
        
              $datediff = date("z", $dateto) - date("z", $datefrom);
              break;
        
            case "d": // Number of full days
        
              $datediff = floor($difference / 86400);
              break;
        
            case "w": // Number of full weekdays
        
              $days_difference = floor($difference / 86400);
              $weeks_difference = floor($days_difference / 7); // Complete weeks
              $first_day = date("w", $datefrom);
              $days_remainder = floor($days_difference % 7);
              $odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
              if ($odd_days > 7) { // Sunday
                $days_remainder--;
              }
              if ($odd_days > 6) { // Saturday
                $days_remainder--;
              }
              $datediff = ($weeks_difference * 5) + $days_remainder;
              break;
        
            case "ww": // Number of full weeks
        
              $datediff = floor($difference / 604800);
              break;
        
            case "h": // Number of full hours
        
              $datediff = floor($difference / 3600);
              break;
        
            case "n": // Number of full minutes
        
              $datediff = floor($difference / 60);
              break;
        
            default: // Number of full seconds (default)
        
              $datediff = $difference;
              break;
          }    
        if($datediff==0)
            $datediff=1;
          
              return $datediff;
        
        }     
        function count_booking_id($id)
        {
            $s = substr($id,3,strlen($id)) + 1;
            $s = substr($id,0,3).$s;
            return $s;
        }
        /**
         * @name calc_due_date()
         * @created February 21, 2003
         * @author J de Silva
         * @modified July 30, 2004
         * ------------------------------------------------------------------
         */
        function date_add( $date, $interval, $add, $return_date_format='Y-m-d' )
        {
          $date  =  strtotime( $date );
          if( $date !== -1 )
          {
            $date  =  getdate( $date );
            switch( strtolower($interval) )
            {
              case  'month'  :  $date['mon']  +=  $add;  break;
              case  'day'    :  $date['mday'] +=  $add;  break;
              default        :  $date['year'] +=  $add;
            }
            return( date($return_date_format, mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])) );
          }
          return( false );
        }
        function convert_url($url)
        {
            //http://
            $final_str = $url;
            if(substr($url,0,7)=="http://")
            {    
                $final_str = substr($url,7);
            }
            if(substr($final_str,0,4)!="www.")
            {
                $final_str = "www.".$final_str;
            }
            return $final_str;
        }
        function convert_url1($url)
        {
            $final_str = $url;
            if(substr($url,0,7)!="http://")
            {    
                $final_str = "http://".$url;
            }
            
            if(substr($final_str,7,4)!="www.")
            {
                $final_str = "http://www.".substr($final_str,7);
            }
            return $final_str;
        }
    ?>
    
    Code (markup):
    index.php
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script language="javascript" src="include/function.js"></script>
    <script type="text/javascript" language="javascript">
        var request = makeObject();
        function makeObject()
        {
            var x;
            var browser = navigator.appName;
            if(browser == "Microsoft Internet Explorer")
            {
                x = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else
            {
                x = new XMLHttpRequest();
            }
            return x;
        }
        function get_value()
        {
            if(space_deduct(document.frmhttpheaders.url.value)==" ")
            {
                alert("Plese enter domain name to check ");
                document.frmhttpheaders.url.focus()
            }
            else
            {
                
                request.open('get', 'check_http_header.php?url=' + document.frmhttpheaders.url.value +'&v_code='+ document.frmhttpheaders.v_code.value);
                request.onreadystatechange = parseInfo;
                request.send('');
                return false;
            }
        }
        function parseInfo()
        {
            if(request.readyState == 1)
            {
                document.getElementById('my_div').innerHTML = 'Checking.......';
            }
            if(request.readyState == 4)
            {
                var answer = request.responseText;
                document.getElementById('my_div').innerHTML = answer;
            }
        }
    </script>
    <link href="assets/standard.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <table>
            <tr>
               <form action="" method="post" name="frmhttpheaders">
                 <td align="center" class="table-footerbg-lightgrey"><table width="100%"  border="0" cellspacing="1" cellpadding="2">
                   <tr valign="top">
                     <td width="80" align="left"><strong>Enter URL</strong></td>
                     <td width="450" align="left"><input name="url" type="text" class="input-box-up" onFocus="event.srcElement.className='input-box-down';" onBlur="event.srcElement.className='input-box-up';" size="40" />                                                 </td>
                   </tr>
                    <tr>
                     <td><strong>Verification</strong></td>
                     <td valign="bottom"><input name="v_code" type="text"  class="input-box-up" onFocus="event.srcElement.className='input-box-down';" onBlur="event.srcElement.className='input-box-up';" value="" size="40" />
                     <img src="include/image_verification.php" align="absbottom" /></td>
                   </tr>
                  
                   <tr>
                     <td>&nbsp;</td>
                     <td>&nbsp;</td>
                   </tr>
                   <tr>
                     <td>&nbsp;</td>
                     <td align="left"><input type="button" name="Submit" value="View Now" class="input-button-red" onClick="get_value()" /></td>
                   </tr>
                   <tr>
                     <td>&nbsp;</td>
                     <td align="left">&nbsp;</td>
                   </tr>
                       <tr>
                           <td colspan="2" ><div id="my_div"></div></td>
                     </tr>
                 </table>                                            </td>
                </form> 
               </tr>
        </table>
    </body>
    </html>
    
    Code (markup):
    ...

    please download attach to full view
     

    Attached Files:

    baotram, Feb 25, 2013 IP