본문 바로가기

개발도구/PHP,ASP,JSP,SCRIPT

[PHP]Twitter 나 facebook 에 보낼때 주소를 짧게 암호화처럼 보내기

<area shape="rect" coords="114,58,148,118" href="/twitter.php?no=<?=$no?>&category=<?=$category?>&type=<?=$type?>&msg=<?=urlencode($arrData[m_srv_title]."+#XXToday")?>" alt="트위터" />]

위처럼 twitter.php 파일에 값들을 보내게 되면 
받은 파라메터 값으로 아래처럼 처리

그럼 보내는 값은 http:mtz.kr/x32ad$ 이러하게 변환할수 있다.  

$type = $_GET[type];
$msg = urldecode($_GET[msg]);
$no = $_GET[no];


if($type=="3"){
$sendUrl = $mobileUrl."/redirect.html?param=twitter|http://xxxx.co.kr/stview.php?no=".$no."%26web";
}else if($type=="4"){
$sendUrl = $mobileUrl."/redirect.html?param=twitter|http://xxx.co.kr/mnbview.php?no=".$no."%26web";
}.
.
.
.
 
 
/* make a URL small */
function make_mtz_url($url,$id,$pw,$format = 'xml',$version = '1.0.1')
{
//create the URL
global $wwwUrl;
if(strpos($wwwUrl,"nwww") > 0){
$domain = "http://mtz.kr";
}else{
$domain = "http://mtz.kr";
}


$mtzapp = $domain.'/yourls-api.php?action=shorturl&url='.$url.'&version='.$version.'&username='.$id.'&password='.$pw.'&format='.$format;
//get the url
//could also use cURL here
$response = file_get_contents($mtzapp);


//parse depending on desired format
//if(strtolower($format) == 'json')
//{
$json = @json_decode($response,true);

//print_r2_web($json);
if($json['statusCode']=='200'){
return $json['shorturl'];
}else{
$url_array = explode("|",$url);
return $url_array[1];
}
//}
//else //xml
//{
// $xml = simplexml_load_string($response);
// return 'http://n.mtz.kr/'.$xml->results->nodeKeyVal->hash;
//}
}
 


$short = make_mtz_url($sendUrl,'mttyyy','dpaxl','json');

$url = "http://mobile.twitter.com/home?status=".urlencode(stripslashes(iconv("euc-kr", "utf-8",$msg)))."+".$short;

header("Location: $url");