note 53445 modified in ref.curl by danbrown

From: Date: Sun, 17 May 2009 19:38:11 +0000
Subject: note 53445 modified in ref.curl by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155246@lists.php.net to get a copy of this message
Problems can occur if you mix CURLOPT_URL with a 'Host:' header in CURLOPT_HEADERS on redirects because cURL will combine the host you explicitly stated in the 'Host:' header with the host from the Location: header of the redirect response. In short, don't do this: <?php $host = "www.example.com"; $url = "http://$host/"; $headers = array("Host: $host"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); Do this instead: $host = "www.example.com"; $url = "http://$host/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); ?> --was-- Problems can occur if you mix CURLOPT_URL with a 'Host:' header in CURLOPT_HEADERS on redirects because cURL will combine the host you explicitly stated in the 'Host:' header with the host from the Location: header of the redirect response. In short, don't do this: $host = "www.dontusehostheaders.com"; $url = "http://$host/"; $headers = array("Host: $host"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); Do this instead: $host = "www.dontusehostheaders.com"; $url = "http://$host/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); http://php.net/manual/en/ref.curl.php

« previous php.notes (#155246) next »