newbie: php problem in protected directory
Moderator: General Moderators
newbie: php problem in protected directory
In a via .htaccess password protected directory (Apache version 1.3.14/PHP 4.1.2)) I get error
'Supplied argument is not a valid File-Handle resource'
in this line of my php script:
$fd= fread(fopen($HTTP_REFERER, "r"), 100000);
What should I do to get this work in the password protected directory?
HTTP_REFERER echo is OK.
Script is in same directory. Works fine in any other (not protected) directory
Am newbie, help most wanted.
Thanks for your attention.
'Supplied argument is not a valid File-Handle resource'
in this line of my php script:
$fd= fread(fopen($HTTP_REFERER, "r"), 100000);
What should I do to get this work in the password protected directory?
HTTP_REFERER echo is OK.
Script is in same directory. Works fine in any other (not protected) directory
Am newbie, help most wanted.
Thanks for your attention.
Thanks for your response.
OK, I put the same script and a testfile in a test dir @
http://www.purplespirit.com/test/test.htm
username: test
password:PHPDN
Click link 'printerfriendly version' and see the error on line 2.
Line 2 in my script is:
$fd= fread(fopen($HTTP_REFERER, "r"), 100000);
No such error when I put this file and script in a not protected dir
I guess I need a wrapper for this script to get it straight in the password protected dir
OK, I put the same script and a testfile in a test dir @
http://www.purplespirit.com/test/test.htm
username: test
password:PHPDN
Click link 'printerfriendly version' and see the error on line 2.
Line 2 in my script is:
$fd= fread(fopen($HTTP_REFERER, "r"), 100000);
No such error when I put this file and script in a not protected dir
I guess I need a wrapper for this script to get it straight in the password protected dir
Try this:
Code: Select all
$file = substr($HTTP_REFERER, strrpos($HTTP_REFERER,"/")+1);
$fd= fread(fopen($file, "r"), 100000);
Last edited by Wayne on Thu Jul 04, 2002 10:41 am, edited 2 times in total.
you are closing your quotes in the wrong place. check them.
And when you put the back link in just append http://www.purplespirit.com to it.
And when you put the back link in just append http://www.purplespirit.com to it.
Thanks for your patiende. Yes, maybe I did mess up, but counting and checking did not give me any clue.
Here is the full script:
<?php
$file = substr($REQUEST_URI, strrpos($REQUEST_URI,"/")+1);
$fd= fread(fopen($file, "r"), 100000);
if ($fd)
{
$start= strpos($fd, "<!--tekst-->");
$finish= strpos($fd, "<!--/tekst-->");
$length= $finish-$start;
$code=Substr($fd, $start, $length);
$start= strpos($fd, "<title>");
$finish= strpos($fd, "</title>");
$length= $finish-$start;
$titel=Substr($fd, $start, $length);
$start= strpos($fd, "<!--updated-->");
$finish= strpos($fd, "<!--/updated-->");
$length= $finish-$start;
$datum=Substr($fd, $start, $length);
}
echo '<html>
<head>
'.$titel.'</title>
</head>
<body bgcolor="silver" leftmargin="30" topmargin="20" rightmargin="30" bottommargin="20" marginwidth="30" marginheight="20" link="#0099cc" vlink="#000066" alink="#9966cc">
<font face="Arial, Helvetica, sans-serif" color="purple">
'.$code.'
<p align="left"><i>back to original version: <a href="'.$HTTP_REFERER.'"> '.$HTTP_REFERER.' </a></i></p>
<p>'.$datum.'</p>
</font>
</body>
</html>';
?>
Here is the full script:
<?php
$file = substr($REQUEST_URI, strrpos($REQUEST_URI,"/")+1);
$fd= fread(fopen($file, "r"), 100000);
if ($fd)
{
$start= strpos($fd, "<!--tekst-->");
$finish= strpos($fd, "<!--/tekst-->");
$length= $finish-$start;
$code=Substr($fd, $start, $length);
$start= strpos($fd, "<title>");
$finish= strpos($fd, "</title>");
$length= $finish-$start;
$titel=Substr($fd, $start, $length);
$start= strpos($fd, "<!--updated-->");
$finish= strpos($fd, "<!--/updated-->");
$length= $finish-$start;
$datum=Substr($fd, $start, $length);
}
echo '<html>
<head>
'.$titel.'</title>
</head>
<body bgcolor="silver" leftmargin="30" topmargin="20" rightmargin="30" bottommargin="20" marginwidth="30" marginheight="20" link="#0099cc" vlink="#000066" alink="#9966cc">
<font face="Arial, Helvetica, sans-serif" color="purple">
'.$code.'
<p align="left"><i>back to original version: <a href="'.$HTTP_REFERER.'"> '.$HTTP_REFERER.' </a></i></p>
<p>'.$datum.'</p>
</font>
</body>
</html>';
?>
Sorry my mistake replace this line
with
Code: Select all
$file = substr($REQUEST_URI, strrpos($REQUEST_URI,"/")+1);Code: Select all
$file = substr($HTTP_REFERER, strrpos($HTTP_REFERER,"/")+1);