首页 > 编程技术 > php

php 常用获取服务器变量代码

发布时间:2016-11-25 15:13

php 常用获取服务器变量代码


define('IP', ip());
define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
define('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : preg_replace("/(.*).php(.*)/i", "\1.php", $_SERVER['PHP_SELF']));
define('QUERY_STRING', $_SERVER['QUERY_STRING']);
define('PATH_INFO', isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '');
define('DOMAIN', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : preg_replace("/([^:]*)[:0-9]*/i", "\1", $_SERVER['HTTP_HOST']));
define('SCHEME', $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
define('SITE_URL', SCHEME.$_SERVER['HTTP_HOST'].PHPCMS_PATH);
define('RELATE_URL', isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : SCRIPT_NAME.(QUERY_STRING ? '?'.QUERY_STRING : PATH_INFO));
define('URL', SCHEME.$_SERVER['HTTP_HOST'].RELATE_URL);
define('RELATE_REFERER',urlencode(RELATE_URL));

php imagecreate图片生成代码


if(isset($gd) && $gd==1 && $txt)
{
 header ("Content-type: image/png");
 $txt = urldecode(phpcms_auth($txt, 'DECODE', AUTH_KEY));
 $imageX = strlen($txt)*9;
 $im = @imagecreate ($imageX, 16) or die ("Cannot Initialize new GD image stream");
 $bgColor = ImageColorAllocate($im,255,255,255);
 $white=imagecolorallocate($im,234,185,95);
 $font_color=imagecolorallocate($im,0x00,0x00,0x00);
 
 $fontfile = PHPCMS_ROOT."include/fonts/simfang.ttf";
 if(file_exists($fontfile) && !preg_match('/([a-z0-9@.])/',$txt))
 {
  $txt = iconv("GB2312","UTF-8",$txt);
  ImageTTFText($im, 10, 0, 0, 12, $font_color, $fontfile, $txt);
 }
 else
 {
  $fonttype = intval($fonttype);
  imagestring ($im, $fonttype, 0, 0,$txt, $font_color);
 }
 imagepng ($im);
 imagedestroy ($im);
}

mysql 查询数据库返回mysql_num_rows记录


 function getCityId( $cd )
 {
  $sql = "Select id,cntitle from zgy_classplace where cntitle='$cd' ";
  $result  = mysql_query( $sql ) or die( mysql_error());
  if( mysql_num_rows($result ) )
  {
   $rs = mysql_fetch_array( $result );
   return $rs['id'];
  }
  else
  {
   return 1;
  }
  mysql_free_result( $result );
 }

本站原创转载注明来自www.111cn.net/phper/php.html

php switch break case 使用教程

php switch break case  使用教程

switch在很多语言中都会有只是表达试不一样了,下面我们来看看break case

 /*
   1,600-800^2,800-1000^3,1000-1200^4,1200-1500^5,1500-2000^6,2000-3000^7,3000-5000^8,5000-8000^9,8000-10000
  
   根据mssql用户输入的数据进行分析判断给my数据库
   */
   function aryid( $num )
   {
    if( $num >=600 && $num <801 )
  {
   return 1;
  }
  elseif( $num >800 && $num <1001 )
  {
   return 2;
  }
  elseif( $num >1000 && $num < 1201)
  {
   return 3;
  }
  elseif( $num >1200 && $num <1501 )
  {
   return 4;
  }
  elseif ( $num >1500 && $num < 2001 )
  {
   return 5;
  }
  elseif ( $num >2000 && $num <3001 )
  {
   return 6;
  }
  elseif ( $num >3000 && $num <5001)
  {
   return 7;
  }
  elseif ( $num > 5000  && $num <8001 )
  {
   return 8;
  }
  elseif ( $num >8000 && $num <10001 )
  {
   return 9;
  }
  else
  {
   return '';
  }
   }
本站原创转载注明来自www.111cn.net/phper/php.html

fck调用与使用方法


function load($areaname){
   $this->initialize($areaname);
   return $this->loadhtml() ;
  }

  function loadhtml(){
   $htmlareavalue = htmlspecialchars($this->areavalue) ;
   $html = '<div>' ;
   if ($this->browsers()){
    if (isset($_GET['fcksource']) && $_GET['fcksource'] == "true"){
     $File = 'fckeditor.original.html' ;
    }else{
     $File = 'fckeditor.html' ;
    }
    $Link = "{$this->rooteditor}editor/{$File}?InstanceName={$this->areaname}";
    if ($this->bottontype != ''){
     $Link .= "&amp;Toolbar={$this->bottontype}";
    }
    $html .= "<input type="hidden" id="{$this->areaname}" name="{$this->areaname}" value="{$htmlareavalue}" style="display:none" />";// Render the linked hidden field.
    $html .= "<input type="hidden" id="{$this->areaname}___configure" value="" . $this->loadconfigure() . "" style="display:none" />";// Render the configurations hidden field.
    $html .= "<iframe id="{$this->areaname}___Frame"" width=100% src="{$Link}" width="{$this->areawidth}" height="{$this->areaheight}" frameborder="0" scrolling="no"></iframe>";// Render the editor IFRAME.
   }else{
    if (strpos($this->areawidth,'%') === false){
     $areawidthCSS = $this->areawidth . 'px' ;
    }else{
     $areawidthCSS = $this->areawidth;
    }
    if ( strpos( $this->areaheight, '%' ) === false){
     $areaheightCSS = $this->areaheight . 'px' ;
    }else{
     $areaheightCSS = $this->areaheight ;
    }
    $html .= "<textarea name="{$this->areaname}" rows="4" cols="40" style="width: {$areawidthCSS}; height: {$areaheightCSS}">{$htmlareavalue}</textarea>" ;
   }
   $html .= '</div>' ;
   return $html ;
  }

function initialize($areaname){
   global $urlconf;
   $this->areaname   = $areaname ;
   $this->rooteditor  = $urlconf['domains'].'textarea/fck/' ;
   $this->areawidth  = '100%';
   $this->areaheight  = '400px';
   $this->bottontype  = 'Default';
   $this->areavalue  = $this->areavalue ? $this->areavalue : '';
   $this->configure  = array() ;
  }

  function dater($data){
   $this->areavalue = stripslashes($data);
  }

标签:[!--infotagslink--]

您可能感兴趣的文章: