visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Getting around .htaccess using cURL


By: Trollio U.S.A.  Date: 28/04/2003 00:00:00  English  Points: 125 Status: Answered
Quality : Excellent
I want to automate a php script that I'm running, however I must keep it behind
a .htacess protected directory.

Is there a way to validate against a .htaccess file using PHP (preferably with cURL).


Never mind. I found the answer myself. No need to respond to this question.
By: VGR Date: 28/04/2003 09:23:00 English  Type : Comment
so the answer is ?!?
By: Trollio Date: 28/04/2003 10:50:00 English  Type : Comment
Answer is:

$url = "<A HREF="http://url.com/your.htaccess">http://url.com/your.htaccess</a> dir/";
$HTTPS_USER = "whatever";
$HTTPS_PWD = "whatever";

$ch = curl_init("$url");

curl_setopt($ch, CURLOPT_USERPWD,"$HTTPS_USER:$HTTPS_PWD");
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$tempfile = "file.zip";
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file'=>"@$tempfile"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


$results = curl_exec($ch);
//do whatever you want with the $results

curl_close($ch);
By: VGR Date: 28/04/2003 16:59:00 English  Type : Comment
thank you. I'll now try to understand what it does :D
By: RQuadling Date: 29/04/2003 18:35:00 English  Type : Comment
Would ...


$fp = fopen("<A HREF="http://">http://</a>{$HTTPS_USER}:{$HTTP_PWD}@url.com/your.htaccess_dir/file.zip");

not do the trick too?

Saves on curl.

NOTE: Not tested.

Richard.
By: Trollio Date: 29/04/2003 18:58:00 English  Type : Comment
I tried fopen, but couldn't seem to get it to work.
That said, I don't know why it wouldn't. You may have better luck.

By: VGR Date: 29/04/2003 19:12:00 English  Type : Answer
perhaps use HTTP basic authentication, no ?

$_SERVER['PHP_AUTH_USER']
and
$_SERVER['PHP_AUTH_PW']


Example 16-1. HTTP Authentication example

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>



By: Trollio Date: 05/05/2003 11:58:00 English  Type : Comment
I tested with HTTP Authentication and was successful with that as well.

Thanks!

Do register to be able to answer

EContact
browser fav
page generated in 350.000860 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page