2
我需要從列中提取每個域,並在每個域上CURL以便更改列中的特定域正確的那一個。從MySQL中的列獲取每一行,並在每個域上CURL並使用新獲取的域更改行
例:example.test.com =>檢查訪問的訪問並找到它重定向=>獲取重定向域=>從DB改變存在的域名與域名重定向
我曾嘗試做一些僞代碼,但我還是需要一些幫助,因爲我不必爲了使用PHP和MySQL足夠的經驗來完成這件事:
// 1. Connect to DB
// 2. Interogate DB and get an array which contains every URLs
// 3. For each URL in the array call the getRedirectUrl($url) function with the URL as parameter
// 4. Save URL in the DB
$url = 'http://www.example.com';
function getRedirectedUrl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch);
$finalUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
return rtrim($finalUrl,'/');
}
// Verify the response
var_dump(getRedirectedUrl($url));
如果你可以給我一些意見,我真的很感激!
能否請您介紹一下表名和列名檢索? –
表名:商店 專欄:shop_url –
只需替換SELECT id,shop_url從商店和更新商店SET shop_url =:url WHERE id =:id。您必須在生產中將另一個文件的參數設置爲另一個文件 –