Hey there, I am trying to build some kind of point system for twitter, For that i need to shorten a specific url. this one http://a.gd/?module=ShortURL&file=Add&mode=API&url=UNIQUE URL How can i send and recieve the shortend url? tried something with $_GET but not really working! Anyone got a solution? thanks <? $longurl = http://a.gd/?module=ShortURL&file=Add&mode=API&url=UNIQUE URL; $shorturl = $_GET[$longurl]; ?> PHP: but not working...
$_GET helps to retrieve the name/value parameter from an URL. For shortening the urls may be you could use a MySql interface through which you could store an unique shortened url for each of those long urls. example: http://mysite.com/link1 redirects to http://mysite.com/index.php?id=1&product=50&others=blahblah
Hey, you should read about fopen or curl P.S. Example: <?php $longUrl = "http://google.com"; $f = fopen ("http://a.gd/?module=ShortURL&file=Add&mode=API&url=".$longUrl, "r"); $shotUrl = fgets($f, 2000); fclose($f); echo $shotUrl; ?> PHP:
hi to extract the variables use this function getVariableFromUrl($url) { //we need to see if this URL is passing any GET variables $variablesStart = strpos($url, "?") + 1; if (!$variablesStart) { // no variables! return(false); } //before we extract the variables, we need to remove any anchors $variablesEnd = strpos($url,"#",$variablesStart); if ($variablesEnd) { $getVariables = substr($url, $variablesStart, $variablesEnd - $variablesStart); } else { $getVariables = substr($url, $variablesStart); } //next, we split the URL into an arrays containing variable name and value pairs (ie. "variable=value") $variableArray = explode("&", $getVariables); //we will iterate through each of the array pairs (ie. "variable=value") foreach ($variableArray as $arraySet) { $nameAndValue = explode("=", $arraySet); //using the above examples, $nameAndValue[0] would be "variable" and $nameAndValue[1] would be "value" $output[$nameAndValue[0]] = $nameAndValue[1]; } return($output); } $longurl = http://a.gd/?module=ShortURL&file=Add&mode=API&url=UNIQUE URL; $shorturl = getVariableFromUrl[$longurl]; print_r($shorturl); // or use //echo $shorturl[4]; //to print 5 element in long url I hope that helps Regards Alex PHP:
please give us more description that you want. it does not matter shortened or long url. you can send url using this format: <a href="http://www.target.com/?url=yourshortaned url">Send url</a> now tell me what's the source of long url?
i suppose: 1. http://a.gd - service which makes "short url" from "long url" http://a.gd/?module=ShortURL&file=Add&mode=API&url=LONG_URL replace LONG_URL with real url (http://google.com) and write in browser you get a short url. And i think need this proccess, but on php language ;-) P.S. See my previouses posts
i guest like this too ... or, maybe this (?) -> 1. you have URL = http://a.gd/?module=ShortURL&file=Add&mode=API&url=LONG_URL 2. you want to catch the LONG_URL so, just put -> $result = $_GET['url'];