PHP CURL Follow Redirect

I am writing a section of code the gets a page that is out on the Internet. When php curl goes to this page it redirects to another page. I am not sure what type of redirect it is. In other words I don’t know if it is a 301.

Here is the initial page my script goes to.

https://billing.joesdatacenter.com/cart.php?a=add&pid=2&cf_wdcmaid=971

I believe it redirects to a dynamic page. I need to be able to follow this redirect. I have included my code which includes the curl redirect. The problem is that even with the line of code to follow redirects it does not follow the redirect. I use an array with url’s in the script in place of the url. To understand how the redirect happens you can go to the url I provided.


$page = curlGetPage($ch, $serverUrl[$prodId]);


function curlGetPage($ch, $url){
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
   $data = curl_exec($ch);
   return $data;
}

Well considering the link goes to a “This server is no longer available” page, i’m gonna ask… are you SURE you’re going to the right address?

I am going to the right address. It is just that server is no longer available. I check in my script looking for a needle in a haystack to see whether to set the server in or out of stock on my site. The thing that baffles me is that I am using follow location and it does not seem to go to the page that either lets me order a server or says it is no longer available. This particular just checks to see if the server is available or not.

I ran into a problem. After the redirect it does not redirect to the page that says the server is no longer available. It redirects to the home page. I used the following code to see.

echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

It should follow location from

https://billing.joesdatacenter.com/cart.php?a=add&pid=2&cf_wdcmaid=1659

to

cart.php?a=confproduct&i=0

Instead it redirects to the home page. Being the change in url is still on the cart.php script is it possible I don’t need follow location, instead another way?

This site may be useful in tracing the http_responses especially the verbose option:

https://supiet2.tk/test?

I am running into some more issues. When I test a url at the site mentioned above aka https://supiet2.tk/test ? all the server pages go to the same url for servers that are out of stock. This happens even on servers that are in stock that all redirect to different url’s. Check out this page and follow the redirects so you can see what I mean.

Then test a few of the urls at the above site. The problem I am having is that I need to redirect to the page that my browser goes to when I use firefox. My script is not redirecting that page in the case where the server is in stock. When the server is out of stock I get the right url with curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);. But for some reason when I echo to the screen the contents of that page I get nothing. Here is ho0w I do the echo. In turn when I search for a needle in a haystack it does not find my string.

Here is some code.

echo $page = curlGetPage($ch, $serverUrl[$prodId]);
			   echo "<br> redirect url " . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
			   echo "breaker <br><br>";
			   $pResult = strpos( $page, $needle );