2009-08-14 29 views
9

Tôi đang phát triển tập lệnh php để xóa trang web này và gửi email cho tôi dữ liệu cho tôi. Dường như đăng nhập chính xác vì khi tập lệnh chạy, có vẻ như chuyển hướng và cho tôi một thông báo cho biết Object đã di chuyển ở đây và đây là liên kết đến trang default.aspx, đó là điều chính xác xảy ra khi tôi đăng nhập theo cách thủ công.php ssl curl: lỗi di chuyển đối tượng

Dưới đây là kịch bản của tôi:

<?php 
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; 

// INIT CURL 
$ch = curl_init(); 

//init curl 
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 

// SET URL FOR THE POST FORM LOGIN 
curl_setopt($ch, CURLOPT_URL, 'https://access.manager.com/Login.aspx'); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 

// Set your login and password for authentication 
curl_setopt($ch, CURLOPT_USERPWD, 'testu:passwd'); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 


// This is occassionally required to stop CURL from verifying the peer's certificate. 
// CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if 
// CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a 
// common name and also verify that it matches the hostname provided) 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

// Optional: Return the result instead of printing it 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

// ENABLE HTTP POST 
curl_setopt ($ch, CURLOPT_POST, 1); 

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD 
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'Username=testu&Password=passwd'); 

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL 
# not to print out the results of its query. 
# Instead, it will return the results as a string return value 
# from curl_exec() instead of the usual true/false. 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 

// EXECUTE 1st REQUEST (FORM LOGIN) 
$store = curl_exec ($ch); 
echo $store; 
// CLOSE CURL 
curl_close ($ch); 

?> 

bất kỳ ý tưởng gì có thể ngăn trang để sản xuất các trang một cách chính xác? Tôi đoán nó không chuyển hướng chính xác.

cảm ơn trước

Trả lời

11
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 

Thay đổi đó để 1. Ngoài ra, thiết lập này sau CURLOPT_SSL_VERIFYPEER:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
+0

tuyệt vời! đã sửa nó. – phill

+0

Ngoài ra, hãy xem CURLOPT_MAXREDIRS bạn có thể phải sử dụng nó (trong tương lai?). –

+1

Tại sao? Tại sao người dùng nên thêm/thay đổi những điều này? –

2

Bạn có thể sử dụng như sau:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_MAXREDIRS,5); // return into a variable 
+0

@ jeffrey-roosendaal cảm ơn vì đã chỉnh sửa. –

Các vấn đề liên quan