Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Вопросы по cURL
Форумы портала PHP.SU » » HTTP и PHP » Вопросы по cURL

Страниц (1): [1]
 

1. Jnas - 02 Сентября, 2011 - 05:39:58 - перейти к сообщению
Здравствуйте, уважаемые форумчанины.

Прошу камня не кидать, только учусь...

Когда то нужно было сделать быстро быстро авторизацию на определенном сайте, признаюсь - для парсинга...
Тогда я не смог понять почему так вышло - не работала, но вставив один и тот же код 3 раза (не помню как так вышло, причем 2 раза вставив не пошло). Работала и вроде до сих пор работает, но вот сегодня про него вспомнил, и опять не смог разобраться в чем дело, ув. форумчанины помогите, где в коде ошибка, что не так.

Вот этот код принимаю на $file_site_st получаю не залогиневшую страницу :
PHP:
скопировать код в буфер обмена
  1.  
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL,$login_url_st);
  4. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  5. curl_setopt($ch, CURLOPT_REFERER, $referer_st);
  6. curl_setopt($ch, CURLOPT_POST, 1);
  7. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_st);
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9. curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
  10. curl_setopt($ch, CURLOPT_HEADER, 0);
  11. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/st.txt');
  12. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/st.txt');
  13. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  14. curl_setopt ($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
  15. curl_setopt($ch, CURLOPT_URL,$ssilka);
  16. $file_site_st = curl_exec($ch);
  17.  


Вот этот код принимаю, на $file_site_st получаю залогиневшую страницу, если закомментировать 14 и 30 строку (которая вроде бы никакой роли не играет) , то уже не залогиневшую страницу получаю :

PHP:
скопировать код в буфер обмена
  1.  
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL,$login_url_st);
  4. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  5. curl_setopt($ch, CURLOPT_REFERER, $referer_st);
  6. curl_setopt($ch, CURLOPT_POST, 1);
  7. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_st);
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9. curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
  10. curl_setopt($ch, CURLOPT_HEADER, 0);
  11. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/st.txt');
  12. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/st.txt');
  13. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  14. curl_setopt ($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
  15. $sslk = curl_exec($ch);
  16.  
  17. $ch = curl_init();
  18. curl_setopt($ch, CURLOPT_URL,$login_url_st);
  19. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  20. curl_setopt($ch, CURLOPT_REFERER, $referer_st);
  21. curl_setopt($ch, CURLOPT_POST, 1);
  22. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_st);
  23. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  24. curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
  25. curl_setopt($ch, CURLOPT_HEADER, 0);
  26. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/st.txt');
  27. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/st.txt');
  28. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  29. curl_setopt ($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
  30. $sslk = curl_exec($ch);
  31.  
  32. $ch = curl_init();
  33. curl_setopt($ch, CURLOPT_URL,$login_url_st);
  34. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  35. curl_setopt($ch, CURLOPT_REFERER, $referer_st);
  36. curl_setopt($ch, CURLOPT_POST, 1);
  37. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_st);
  38. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  39. curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
  40. curl_setopt($ch, CURLOPT_HEADER, 0);
  41. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/st.txt');
  42. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/st.txt');
  43. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  44. curl_setopt ($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
  45. curl_setopt($ch, CURLOPT_URL,$ssilka);
  46. $file_site_st = curl_exec($ch);
  47.  


почему так?
2. DeepVarvar - 02 Сентября, 2011 - 07:30:52 - перейти к сообщению
Jnas пишет:
почему так?
потому, что оно по вашему никакой роли не играет.
3. Jnas - 02 Сентября, 2011 - 08:22:30 - перейти к сообщению
мдаа...
ответ с "большим" смыслом, сразу понимаешь почему при повторе коде работает, и почему при не повторе не работает))) или даже сразу познаешь истину PHP в таких ответах)))

по факту попрошу Хм

 

Powered by ExBB FM 1.0 RC1