Why doesn’t the script work?

Why doesn’t the script work? In theory, everything is correct.

I didn’t change much, but it still doesn’t work
define(‘EMAIL’, ‘*‘);//login
define(‘PASS’, ‘
***’); //password
define(‘COOKIES’,$_SERVER[‘DOCUMENT_ROOT’].’/cook.txt’);//file to write COOKIES on login

$post = array(
            'act' => 'login',
             'email' => EMAIL,
            'pass' => PASS,
            'pda' => '1',
            'to' => '',
             'from_host' => 'm.vkontakte.ru');
    $auth = vksms_curl('https://login.vk.com/?act=login', $post, 'http://vkontakte.ru/');
 $Page = vksms_curl('https://vkontakte.ru/id19685573');
    if (preg_match('#chas: cur\.decodehash\(\'([^\']+)#i', $Page, $matches))
        $chas = strrev(substr($matches[1],4,13)) . strrev(substr($matches[1],20,25));
        $send = iconv('cp1251', 'utf-8', vksms_curl(
                                'act=a_send&ajax=1&al=1&chas=' . $chas . '&from=box&message=' . urlencode($message) . '&title=' . urlencode($title) . '&to_id=' . $to_id)
        );   echo $send;
        echo preg_match('| |ui', $send);
//    cURL
function vksms_curl($url,$post='',$ref='',$basicAuth=':',$userAgent='Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv: Gecko/20090824 Firefox/3.5.4',$headers=FALSE)
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER,$headers);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_USERAGENT,$userAgent);
    curl_setopt($ch, CURLOPT_ENCODING, 'utf-8');
    curl_setopt($ch, CURLOPT_AUTOREFERER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT,999);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIES);
        curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIES);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_USERPWD, $basicAuth);
    @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
    $data = curl_exec($ch);
    return $data;

Answer 1, authority 100%

The main problem with your script is that you don’t check the result of the called functions. Accordingly, it is impossible to understand where the error is. Well, it may not be necessary to check the result of curl_setopt, although I would check the result for CURLOPT_COOKIEFILE. But the result of curl_exec must be checked, and if something is wrong, display a diagnostic message.

On the subject of actual errors, the following things confused me:

  • The character ‘&’ at the beginning of the $post.
  • line

  • Working with COOKIES. Are you sure that by specifying CURLOPT_COOKIEFILE you can calm down? Will he write new values ‚Äč‚Äčthere? It is reasonable to assume that this function only reads the specified file, but does not write the authorization result there in any way. Do you have this file on disk? What was in it before running the script? After completion?
  • Does the script have permission to write the file to DOCUMENT_ROOT?

One more tip: if you don’t know where the error occurs in the script, you should add a bunch of lines echo “messagen”; between work teams. So you at least know which line the script execution reaches before the error.