Languages :: PHP :: Getting around .htaccess using cURL |
|||
| By: Trollio |
Date: 28/04/2003 00:00:00 |
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 | Type : Comment |
|
| so the answer is ?!? |
|||
| By: Trollio | Date: 28/04/2003 10:50:00 | 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 | Type : Comment |
|
| thank you. I'll now try to understand what it does :D |
|||
| By: RQuadling | Date: 29/04/2003 18:35:00 | 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 | 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 | 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 | Type : Comment |
|
| I tested with HTTP Authentication and was successful with that as well. Thanks! |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








