Get password protected URL folder using PHP fopen function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get password protected URL folder using PHP fopen function
# 1  
Old 11-03-2010
Get password protected URL folder using PHP fopen function

Hi everybody,

Please some help over here, I`m pretty new in PHP.

I have a cronrefresh php file within a website, I need this script get infornation from a URL of the site.

Part of the script where $URL variable appears is:

PHP Code:
$fdURL mysql_query("SELECT * FROM affiliSt_config WHERE name = 'csvURL".$_GET['fd_refresh']."'");
$URL mysql_fetch_assoc($fdURL);
$fdtype mysql_query("SELECT * FROM affiliSt_config WHERE name = 'csvType".$_GET['fd_refresh']."'");
$type mysql_fetch_assoc($fdtype);

    if (
$type['value'] == 'tab') {
    
$type "\t";
    } else {
    
$type $type['value'];
    }

// set row variable and open file
$row intval($pieces[11]);
if (
$URL['title'] == 'Upload ') {
$handle fopen('../'.$URL['value'], "r");
} else {
$handle fopen($URL['value'], "r"); 
But I want to restrict public access to that URL setting up an user and password to access $URL.

I`ve seen fopen documentation and to do this with fopen is needed to embed the user and password like this
PHP Code:
$handle fopen('http://username:password@www.example.com/myfolder','r'); 
but if the URL is stored in the variable $URL I`m not sure how to modify this part of the script in order to don`t affect the rest of the script.

It could be something like this?:

Instead of:
PHP Code:
$handle fopen('../'.$URL['value'], "r");
} else {
$handle fopen($URL['value'], "r"); 
this
PHP Code:
$handle fopen('../'.username:password@$URL['value'], "r");
} else {
$handle fopen(username:password@$URL['value'], "r"); 
or

Instead of:
PHP Code:
$URL mysql_fetch_assoc($fdURL); 
This
PHP Code:
$URL username:password@mysql_fetch_assoc($fdURL); 
Thanks in advance for any help.
# 2  
Old 11-03-2010
When I have a similar requirement with URLs and PHP, I use curl() and not fopen().

curl() has many options, including adding authentication, timeouts, etc.

Cheers.
# 3  
Old 11-03-2010
Hi Neo, thanks for your answer.

My problem is I don´t know how to change the script using fopen or another function and more important, without affect the normal script perfomance.

I try to "enhance" this script I have (I didn`t write it, I`m not familiar with PHP) to be able to do the same operation and to get the same information from the same URL when this URL is protected.

Some help in how to do it would be very appreciated.

Best regards

---------- Post updated at 01:32 PM ---------- Previous update was at 01:51 AM ----------

May somebody help me with my question pleaseSmilie?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Password protected excel file without encryption or zipping

All, I have requirement to send password protected excel file in an email from unix/linux box without zipping it. Any help would be appreciated. Thanks.. (8 Replies)
Discussion started by: Durgesh Gupta
8 Replies

2. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

3. UNIX for Dummies Questions & Answers

SSH - Password Protected Directory Issue

I dug myself a hole yesterday that I can't seem to get myself out of. In a very futile attempt to create a new FTP user with limited access via SSH, I inadvertently changed permissions for who knows what and now I am having a problem accessing password protected directories. When I enter the... (1 Reply)
Discussion started by: HiddenColors
1 Replies

4. UNIX for Dummies Questions & Answers

Unzipping multiple password-protected files

I am trying to unzip ~150 files on a SUN server in Unix via a telnet program (PuTTy), so I am restricted (I believe) to single-line command functions. All of the files are password protected, and each one contains three files. Is there a way to automate the process? I have tried 7z, but that only... (0 Replies)
Discussion started by: Davman
0 Replies

5. Shell Programming and Scripting

Unzipping files <password protected>

Hie Friends, I need your help once again. I have 77 “password protected” winzip files in linux/unix server. I want to decrypt it through an automated script. Password of every file is same and it is mhd*tt. Please help me. Usually I unzip it as follows, manually one by one. unzip <file name> ... (6 Replies)
Discussion started by: anushree.a
6 Replies

6. Shell Programming and Scripting

How to make files/folders Password protected

Any idea how to make files/folders password protected... I dont want to change the permissions of the files/folders... (1 Reply)
Discussion started by: know d unknown
1 Replies

7. Web Development

CAN TCPDF USE fopen() or Convert URL To PDF?

Dear all, I'm a newbie for PHP and TCPDF ,I have to change the URL to PDF, so I used FPDF , But it cannot convert most of the advanced HTML tags. So explored again and found TCPDF , it can do most of the tag but I cannot found to change URL to PDF. So Does anyone can point the example... (0 Replies)
Discussion started by: athae
0 Replies

8. Shell Programming and Scripting

How to make script password protected

Hi All, I want to make my script password protected. i e: if somebody runs my script it should prompt for password. Can somebody help me in to execute the same?? Thanks in Advance :b: (11 Replies)
Discussion started by: achararun
11 Replies

9. UNIX for Dummies Questions & Answers

Print on a printer which is password protected

Hi, I am trying to print from HP unix machine to a Toshiba printer which is password protected. How can I print? Thanks. Anuj (1 Reply)
Discussion started by: Anuj
1 Replies

10. UNIX for Dummies Questions & Answers

I inhereted a Unix server that is password protected...Help!

I inhereted a project server that has UNIX installed with a SCO OS. I am trying to learn UNIX but I cannot go beyond the password and login. The original engineers have left the company and nothing was ever written down. How can access our server? (1 Reply)
Discussion started by: fxsaint
1 Replies
Login or Register to Ask a Question