if($_GET['code']) { $json = @file_get_contents("https://oauth.vk.com/access_token?client_id=$api_id&client_secret=$secret_key&code={$_GET['code']}&redirect_uri=$redirect_uri"); $json_obj = json_decode($json); if($json) { if($json_obj->user_id and $json_obj->access_token) { users::create(array( 'vk_id' => $json_obj->user_id, 'ip_address' => ip_address(), 'date_reg' => full_date(), 'time_reg' => time(), 'group' => 1, 'points' => 300, 'hash' => hash('ripemd160', time()) )); header('Location: /'); } } } 

Strange. But nowhere redirects.

 if($json_obj->user_id and $json_obj->access_token) { 

condition is triggered. If instead of header () put echo 1 ;, then it displays .. Proved header ('Location: /'); exit; but also does not redirect anywhere. What could be the problem?

    1 answer 1

    The fact that you send the headers after you had output to the page, and the warnings that headers already sent you ignore the settings. "To solve this problem, you need the function header () and all the logic that calls it, put BEFORE any output in the browser. Just move it higher in the script. After all, you still redirect the browser. That is, no text will still not be output! So , and there’s no point in outputting something along with the Location header. Properly plan the structure of your script: a block that processes POST should not display anything to the browser. "

    • @stck, thank you. Indeed, there was an error that echo first output, then header - ModaL