passing random variable string into a variable URL

Discussion in 'PHP' started by IamNed, Jun 9, 2010.

  1. #1
    I have two scripts. One is a tinyurl API and the other gnerates random strings. What I want to do it pass a random string into the tiny URL API script such that the tiny URL generated is always different

    
    <?php
    
    function createRandomPassword() { 
    
        $chars = "abcdefghijkmnopqrstuvwxyz023456789"; 
        srand((double)microtime()*1000000); 
        $i = 0; 
        $pass = '' ; 
    
        while ($i <= 7) { 
            $num = rand() % 33; 
            $tmp = substr($chars, $num, 1); 
            $pass = $pass . $tmp; 
            $i++; 
        } 
    
        return $pass; 
    
    } 
    
    // Usage 
    $password = createRandomPassword(); 
    
    ?>
    
    
    <?php
    
    
    //gets the data from a URL  
    function get_tiny_url($url)  
    {  
    	$ch = curl_init();  
    	$timeout = 5;  
    	curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);  
    	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
    	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
    	$data = curl_exec($ch);  
    	curl_close($ch);  
    	return $data;  
    }
    
    //test it out!
    $new_url = get_tiny_url('http://domain.com/?password);
    
    
    echo $new_url
    
    ?>
    Code (markup):
    where it says http://domain.com/?password i want the password value in the first script to be passed before a tiny url is generated

    thanks
     
    IamNed, Jun 9, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    I don't follow? You mean this:

    <?php
    
    function createRandomPassword() { 
    
        $chars = "abcdefghijkmnopqrstuvwxyz023456789"; 
        srand((double)microtime()*1000000); 
        $i = 0; 
        $pass = '' ; 
    
        while ($i <= 7) { 
            $num = rand() % 33; 
            $tmp = substr($chars, $num, 1); 
            $pass = $pass . $tmp; 
            $i++; 
        } 
    
        return $pass; 
    
    } 
    
    // Usage 
    $password = createRandomPassword(); 
    
    //gets the data from a URL  
    function get_tiny_url($url)  
    {  
    	$ch = curl_init();  
    	$timeout = 5;  
    	curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);  
    	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
    	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
    	$data = curl_exec($ch);  
    	curl_close($ch);  
    	return $data;  
    }
    
    //test it out!
    $new_url = get_tiny_url('http://domain.com/?'.$password);
    
    echo $new_url;
    
    ?>
    PHP:
     
    danx10, Jun 9, 2010 IP
  3. IamNed

    IamNed Peon

    Messages:
    2,707
    Likes Received:
    276
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that's what i was looking for. it works. thank you
     
    IamNed, Jun 9, 2010 IP