php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31481 curl isn't following redirects with a relative path
Submitted: 2005-01-11 00:07 UTC Modified: 2010-06-14 01:48 UTC
Votes:6
Avg. Score:4.8 ± 0.4
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:4 (66.7%)
From: jason at merchant dot to Assigned:
Status: No Feedback Package: HTTP related
PHP Version: 4.3.10 OS: Windows XP Pro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jason at merchant dot to
New email:
PHP Version: OS:

 

 [2005-01-11 00:07 UTC] jason at merchant dot to
Description:
------------
I am grabbing an https:// page using curl and that page redirects using a relative path like "/page1.php". curl is failing to follow this path. I have tried replacing the relative path with an absolute path on the page I'm grabbing and that worked so I know the problem lies in the relative path redirection.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-11 04:54 UTC] sniper@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.


 [2005-01-31 22:34 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2010-06-14 00:15 UTC] ktcox at rogers dot com
This Works
<?php
	$addpage = curl_init('http://localhost/updateindex.php');			
	$page = curl_exec($addpage);
	curl_close($addpage);
	echo "$page";
?>

The following don't work.

<?php
	$addpage = curl_init('/updateindex.php');			
	$page = curl_exec($addpage);
	curl_close($addpage);
	echo "$page";
?>

<?php
	$addpage = curl_init('updateindex.php');			
	$page = curl_exec($addpage);
	curl_close($addpage);
	echo "$page";
?>

<?php
	$addpage = curl_init('./updateindex.php');			
	$page = curl_exec($addpage);
	curl_close($addpage);
	echo "$page";
?>
 [2010-06-14 01:48 UTC] rasmus@php.net
Those are not supposed to work.  curl_init() takes a URL.  None of the arguments 
in your example that don't work are URLs.
 [2010-06-14 14:01 UTC] ktcox at rogers dot com
I guess that makes sence.

But is there anyway to curl or any way to http post to a completely offline page?

The following script might help those who would wish to use a relitive url.  It takes the url of the current script and chops off the file name giving you the CWD from the server point of view.

<?php
	$backwards = strrev($_SERVER['PHP_SELF']);	// Get the CWD form the web point of view.
	do
	{
		$char = substr($backwards, 0, 1);
		$backwards = substr($backwards, 1);
	} while (!( $char == '/' )) ;
	$dir = "http://$_SERVER[SERVER_NAME]" . strrev($backwards);
?>

then you would use
curl_init($dir/script.php);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 18:01:34 2024 UTC