Frank Ly
Frank Ly

Reputation: 639

Generate URL with Variable

Hopefully, someone can spot the error, what I need to do is to first fetch the webpage for a token, then curl the new url with the token attached;

here is my code

$text = $siteName;

  if (preg_match('/;t=([a-zA-Z0-9_-]{43})%3D/',$text,$matches)) {
// Match... vjVQa1PpcFMYuRsz10_H-1z41mWWe8d6ENEnBLE7gug
  echo 'TOKEN: '.$matches[1];

$curltube = curl_init ();
curl_setopt ($curltube, CURLOPT_URL, "http://www.veoh.com/watch?v=opQ9GzRe5qs".$matches[1]);
curl_setopt ($curltube, CURLOPT_RETURNTRANSFER, 0 );
curl_setopt ($curltube, CURLOPT_COOKIEFILE, "cookie8.txt"); 
$curltubeplay = curl_exec ($curltube);
curl_close ($curltube);

echo $curltubeplay;
} else {
// No match
}

and the previous code before that fetches the web-page

curl_setopt ($ch, CURLOPT_URL, "http://www.veoh.com/watch?v=opQ9GzRe5qs");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0 );
curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie8.txt"); 

so hopefully, someone can shed some light

Upvotes: 1

Views: 311

Answers (1)

Cal
Cal

Reputation: 7157

My guess (please expand the question to be clear) is that you expect to build a URL like this:

http://www.veoh.com/watch?v=opQ9GzRe5qs;t=abc

But you are building one like this:

http://www.veoh.com/watch?v=opQ9GzRe5qsabc

There are two simple fixes. This one takes the whole matched string, not just the token:

curl_setopt ($curltube, CURLOPT_URL, "http://www.veoh.com/watch?v=opQ9GzRe5qs".$matches[0])

And this one adds back in the missing parts to the URL:

curl_setopt ($curltube, CURLOPT_URL, "http://www.veoh.com/watch?v=opQ9GzRe5qs;t=".$matches[1])

Upvotes: 1

Related Questions