Jump to content

fopen password protected page


lindm

Recommended Posts

Can't get it quite working. So fopen combined with basic authentication only works with ftp (I have not enabled ftp)?? My file is located on the same server...have swtiched safe mode off as well.

 

So question now is: I want to fopen a password protected (basic auth) local file without ftp...how?

 

THanks

Well get the following error:

Warning: fopen(http://[email protected]/htdocs/index.php) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections. in /Library/WebServer/Documents/htdocs/writeform.php on line 21
Unable to open file!

 

I am working on a local environment...could this be a factor?

 

Should perhaps mention I am opening the file to write to it...

Would it perhaps be possible to bypass the authentication for the calling script?

 

Current authentication script:

<?php

if(!isset($_SERVER["PHP_AUTH_USER"])){
    Header("WWW-Authenticate: Basic realm=\"Restricted Access\"");
    Header("HTTP/1.1 401 Unauthorized");
    echo "Authorization missing.";
    exit();
}

$host="xxx.com";
$user="xxx";
$pass="xxx";
$db="xxx";
$table="xxx";
$validate=FALSE;
$path = explode("/", getcwd());
$orgnr=$path[count($path)-1]; //Orgnr is the current folder

$con = mysql_pconnect ("$host", "$user", "$pass") or die("Error: " . mysql_error());
mysql_select_db ("$db");
$result = mysql_query("SELECT * FROM $table Where orgnr = $orgnr");
$row = mysql_fetch_array($result);

if (($_SERVER["PHP_AUTH_USER"]==$row["userName"])&&($_SERVER["PHP_AUTH_PW"]==$row["userPass"])) {$validate=TRUE;} 
mysql_close();

if ($validate==FALSE){
    Header("WWW-Authenticate: Basic realm=\"Restricted Access\"");
    Header("HTTP/1.1 401 Unauthorized");
    echo "Authorization missing.";
    exit();
}
?>

 

Would be

 

<?php
if CALLING SCRIPT IS NOT YYY.php{

if(!isset($_SERVER["PHP_AUTH_USER"])){
    Header("WWW-Authenticate: Basic realm=\"Restricted Access\"");
    Header("HTTP/1.1 401 Unauthorized");
    echo "Authorization missing.";
    exit();
}

$host="xxx.com";
$user="xxx";
$pass="xxx";
$db="xxx";
$table="xxx";
$validate=FALSE;
$path = explode("/", getcwd());
$orgnr=$path[count($path)-1]; //Orgnr is the current folder

$con = mysql_pconnect ("$host", "$user", "$pass") or die("Error: " . mysql_error());
mysql_select_db ("$db");
$result = mysql_query("SELECT * FROM $table Where orgnr = $orgnr");
$row = mysql_fetch_array($result);

if (($_SERVER["PHP_AUTH_USER"]==$row["userName"])&&($_SERVER["PHP_AUTH_PW"]==$row["userPass"])) {$validate=TRUE;} 
mysql_close();

if ($validate==FALSE){
    Header("WWW-Authenticate: Basic realm=\"Restricted Access\"");
    Header("HTTP/1.1 401 Unauthorized");
    echo "Authorization missing.";
    exit();
}
}
?>

What would the changed code be?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.