Redirecting Web Link Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NVPack
Forum Newbie
Posts: 4
Joined: Tue Sep 12, 2006 1:41 pm

Redirecting Web Link Problem

Post by NVPack »

I'm trying to open the following web link. It is linking to a reporting program called Discoverer. When I simply paste the link into my browser, it opens the Discoverer report just like it should. When I try to run this php program, the web link gets redirected (as I interpreted by the dnld.txt output), and the Discoverer report does not get downloaded to the dnld.txt file. I tried to use the 2 commented out curl_setopt options as shown, they did not help. I'll paste the definition of the 2 commented setopts I tried at the bottom just in case it helps.


Here is the code:

Code: Select all

<?php
$fp = fopen("dnld.txt","w");
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://hostname/discoverer4i/viewe
r?us=username&pw=password&db=database&wb=test_download4&fm=txt");
curl_setopt($ch, CURLOPT_FILE, $fp);
##curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
##curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

Here is the output of dnld.txt. It contains the redirected path.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>302 Found</TITLE>
</HEAD><BODY>
<H1>Found</H1>
The document has moved <A HREF="/discoverer4i/viewer?ws=Sheet~201&db=database&
amp;wb=test_download4&fm=txt&us=USERNAME">here</A>.<P>
<HR>
<ADDRESS>Oracle HTTP Server Powered by Apache/1.3.19 Server at <A HREF="mailto:h
martin@blahblah">hostname</A> Port ####</ADDRESS>
</BODY></HTML>
This is not the output I want at all. It is supposed to be a report listing with various columns. Nothing at all like what the output I received. I have also tried to make the format Excel as well. Any ideas? I'm stumped.


CURLOPT_FOLLOWLOCATION: TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).

CURLOPT_UNRESTRICTED_AUTH: TRUE to keep sending the username and password when following locations (using CURLOPT_FOLLOWLOCATION), even when the hostname has changed.


PLease let me know if any further info is needed.

Thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The information their server is giving you would suggest your URL is wrong.
NVPack
Forum Newbie
Posts: 4
Joined: Tue Sep 12, 2006 1:41 pm

Post by NVPack »

I believe the URL itself is good. For example, when I cut and paste the URL straight into a browser, it downloads the report as it should.

So I use that same URL in my php code. However, the message I get has altered the URL in the output message. The code goes in fine by me, but the php part of it wants to change it. Or, it's possible Discoverer is changing it, I don't know.

It changes my URL to this:

Code: Select all

The document has moved <A HREF="/discoverer4i/viewer?ws=Sheet~201&db=database&
amp;wb=test_download4&fm=xls&us=USERNAME">here</A>.<P>
If this is what Discoverer/PHP wants to change the URL to, can I add code to tell the PHP program to go to this new link?
Post Reply