Curl使用curl_getinfo获取url

时间:2016-06-02 08:46:54

标签: php curl

嗨,我知道它是StackOverFlow上一个非常常见的主题。我已经花了整整一周的时间来搜索它。

例如我有一个网址:http://bayja.com/forum/index.php

我希望在发布后发送此网址:http://bayja.com/forum/index.php?topic=3454.0

但现在我得到了http://bayja.com/forum/index.php?board=2.0

我使用$lastUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

我怎样才能得到“http://bayja.com/forum/index.php?topic=3454.0 “?

请帮帮我谢谢。

这是我的代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, "Automatic SMF poster thing");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=".$user."&passwrd=".$password);
curl_setopt($ch, CURLOPT_URL, "$domain?action=login2");
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "$domain?action=post;board=".$board.".0");
$data = curl_exec($ch);
sleep(3);
preg_match('/name="([^"]+)" value="([^"]{32})"/',$data,$sc);
preg_match ( "<input type=\"hidden\" name=\"seqnum\" value=\"(.*)\">", $data, $seqnum);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "topic=".$topic."&subject=".urlencode($subj)."&icon=xx&sel_face=&sel_size=&sel_color=&message=".urlencode($mess)."&message_mode=0&notify=0&lock=0&post_vv[q][4]=๔&post_vv[q][3]=๒&post_vv[q][1]=๔&post_vv[q][2]=๒&additional_options=0&post=xxxxx&".$sc[1]."=".$sc[2]."&seqnum=4&seqnum=".$seqnum[1]);
curl_setopt($ch, CURLOPT_URL, "$domain?action=post2;start=0;board=".$board);
curl_exec($ch);
 $lastUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
 echo $lastUrl; // output "http://bayja.com/forum/index.php?board2" 
 curl_close($ch);

0 个答案:

没有答案