[php] beginner - how to $_GET from other weburl?

Discussion in 'PHP' started by pornorexia, Oct 4, 2009.

  1. #1
    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...
     
    pornorexia, Oct 4, 2009 IP
  2. krishmk

    krishmk Well-Known Member

    Messages:
    1,376
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    185
    #2
    krishmk, Oct 4, 2009 IP
  3. apache

    apache Member

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    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:
     
    Last edited: Oct 4, 2009
    apache, Oct 4, 2009 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #4
    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:
     
    kmap, Oct 4, 2009 IP
  5. apache

    apache Member

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    May be i wrong, but i suppose, that problem is
    , not in extraction variables from url...

     
    apache, Oct 4, 2009 IP
  6. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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?
     
    mdrobiul, Oct 4, 2009 IP
  7. apache

    apache Member

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #7
    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
     
    apache, Oct 5, 2009 IP
  8. nacholibre

    nacholibre Member

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #8
    You'll need database to store the shorten URL's.
     
    nacholibre, Oct 5, 2009 IP
  9. apache

    apache Member

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #9
    Are you kidding or you don't read author's post?
     
    apache, Oct 5, 2009 IP
  10. anest.baik

    anest.baik Peon

    Messages:
    272
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    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'];
     
    anest.baik, Oct 6, 2009 IP
  11. anest.baik

    anest.baik Peon

    Messages:
    272
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    :) i think no need use database
     
    anest.baik, Oct 6, 2009 IP