ajaxでクロスドメイン通信を実現するphp

html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
$(document).ready(function(){
    $('#getbtn').click(function(){
        var url = encodeURIComponent($('#url').val());
        $('#restxt').val('通信中...');
        $.ajax({
            type: "GET",
            url: "ajax.php?url="+url,
            dataType: "text",
            success: function(res){
                $('#restxt').val(res);
            }
        });
    });
});
</script>
</head>
<body>
<p>取得先URL</p>
<input type="text" id="url"></input>
<button id="getbtn">GET</button>
<p>結果領域</p>
<textarea id="restxt" style="width:100%;height:300px;"></textarea>
</body>
</html>

php

<?php
if(isset($_GET["url"]) && preg_match("/^https?:/",$_GET["url"])){

    echo file_get_contents($_GET["url"]);
}else{
    echo "error";
}