Holywhippet
Aug 30th, 2010, 06:50 PM
I've been coding some PHP pages for data entry. One page is meant to be usable from a number of sources - both from other web pages and desktop applications. Basically you feed it some parameters, it enters a record in a database and returns a GUID value.
I need to call this page from another PHP page - both are on the same server in the same directory. The server requires the user to login before they can access the page. This works fine for accessing the PHP page where they enter the data. Problem is, when I try to make it call the PHP page where the data is saved I get authentication errors - presumably because it's running as a user on the server rather than the user they logged in as.
I can kind of get around this by using this function:
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_USERPWD, "uname:pword");
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
Problem is, I have to have my username and password manually entered in the code for this to work and I really don't want to do that. I want it to use the same authentication that is being used to access the first page. Any ideas please?
I need to call this page from another PHP page - both are on the same server in the same directory. The server requires the user to login before they can access the page. This works fine for accessing the PHP page where they enter the data. Problem is, when I try to make it call the PHP page where the data is saved I get authentication errors - presumably because it's running as a user on the server rather than the user they logged in as.
I can kind of get around this by using this function:
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_USERPWD, "uname:pword");
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
Problem is, I have to have my username and password manually entered in the code for this to work and I really don't want to do that. I want it to use the same authentication that is being used to access the first page. Any ideas please?