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

Link to comment
Share on other sites

Well get the following error:

Warning: fopen(http://...@10.0.1.3/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...

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.