Super Include Function

PHP Result Center PHP Result Center เป็นหมวด ที่ไว้รวบรวม โปรแกรม Code php Javascript CSS CMS

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41336
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Super Include Function

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

Super Include Function

โค้ด: เลือกทั้งหมด

<?php

function inc($url,$method='GET'){
    preg_match('/^(((ht|f)tps?):\/\/(.+@)?([^\/]+))?([^\?]+)(\?.+)?/i',$url,$matches);
    $method=($method) ? strtoupper($method) : $method;
    $ssl=(!empty($matches[2]) && preg_match('/s$/i',$matches[2])) ? true : false;
    $domain=(!empty($matches[5])) ? $matches[5] : NULL;
    $path=(!empty($matches[6])) ? $matches[6] : NULL;
    $param=(!empty($matches[7])) ? substr($matches[7],1) : NULL;
    
    if(!$domain){
        if($param){
            foreach(explode('&',$param) as $request){
                list($key,$val)=explode('=',$request);
                if($method=='GET'){
                    $_GET[$key]=$val;
                }
                if($method=='POST'){
                    $_POST[$key]=$val;
                }
            }
        }
        require_once($path);
        if($param){
            foreach(explode('&',$param) as $request){
                list($key,$val)=explode('=',$request);
                if($method=='GET'){
                    unset($_GET[$key]);
                }
                if($method=='POST'){
                    unset($_POST[$key]);
                }
            }
        }
        return true;
    }
    
    else if($domain){
        if($param && $method=='POST' && function_exists('curl_init')){
            $requestUrl=substr($url,0,strpos($url,'?'));
            $ch=curl_init();
            curl_setopt($ch,CURLOPT_URL,$requestUrl);
            curl_setopt($ch,CURLOPT_POST,1);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$param);
            curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

            $content=curl_exec($ch);
            curl_close ($ch);
            echo $content;
        }else{
            echo file_get_contents($url);
        }
        return true;
    }
}

?>

<?php
inc('/var/www/html/example.php');// Normal include
inc('/var/www/html/example.php?a=b&c=d');//GET Request
inc('/var/www/html/example.php?a=b&c=d','POST');//POST Request

inc('http://example.com/');//Other Domain
inc('http://example.com/example.php?a=b&c=d');//GET Request
inc('http://example.com/example.php?a=b&c=d','POST');//POST Request
?>
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 50