Jump to content

How to pass a random string into another variable


Recommended Posts

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

?>

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.