Author Topic: how to fopen a site that requires a username and password ?  (Read 301 times)

0 Members and 1 Guest are viewing this topic.

Offline bidntradeTopic starter

  • Irregular
  • Posts: 8
    • View Profile
I have a site that has a csv feed updated everyday ...

I have a script that i use to parse the csv and update my database
each day . the problem is i must manually download the csv
and upload to my ftp server for the script to work ...

now im using :
Code: (text) [Select]
$handle = fopen("DataFeed.csv", "r");
i would like to be able to pull it directly like this

Code: (text) [Select]
$handle = fopen("http://www.sitenamehere.com/Reseller/Feeds/GetDataFeed.asp?type=csv", "r");
that way it could be run automated each night ....

the problem is the site requires me to login before i have access to the file download...

the site owner said something about : 
Quote
so what you're basically looking for is

How to implement impersonation in an ASP.net application,

not sure what they was talking about ...

are there a way around this ?

Offline JJ2K

  • Enthusiast
  • Posts: 75
    • View Profile
Re: how to fopen a site that requires a username and password ?
« Reply #1 on: July 03, 2009, 02:13:43 PM »
What happens if you do something like:

Code: [Select]
$file = 'http://www.sitenamehere.com/Reseller/Feeds/GetDataFeed.asp?type=csv' ;

$data = file_get_contents($file) or die('Could not read file!');
echo $data;

Is it getting the file

If not don't you have a direct link to the .csv file so you can point it to that
« Last Edit: July 03, 2009, 02:15:01 PM by JJ2K »

Offline bidntradeTopic starter

  • Irregular
  • Posts: 8
    • View Profile
Re: how to fopen a site that requires a username and password ?
« Reply #2 on: July 03, 2009, 02:33:24 PM »
problem is :

the site owner requires a login to there site to access.

no direct link cause its generated dynamically price updates each night ....

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: how to fopen a site that requires a username and password ?
« Reply #3 on: July 03, 2009, 02:43:16 PM »
If you supplied a little more information it would help -

Is the login form an actual form on a web page or is it a HTTP Basic Authentication dialog box (looks like a pop up/alert window)?

Also, if the file was available through FTP, you could just supply the username/password as part of the URL.

In general, you would need to use CURL in order to log into a web page.
« Last Edit: July 03, 2009, 02:43:47 PM by PFMaBiSmAd »
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline bidntradeTopic starter

  • Irregular
  • Posts: 8
    • View Profile
Re: how to fopen a site that requires a username and password ?
« Reply #4 on: July 03, 2009, 03:09:26 PM »
the login is from a Form on the webpage

the form has 2 input boxes :
username
password

the same supplier has a xml url thats not passworded .. but i dont know how to parse xml files ....

but the xml file is 14megs and the csv is 2 megs






Offline mattal999

  • Devotee
  • Posts: 693
    • View Profile
    • Luke Zbihlyj
Re: how to fopen a site that requires a username and password ?
« Reply #5 on: July 03, 2009, 05:50:18 PM »
Well here's my analogy of the solution:

1) Use cURL to call the login page (Not the form, the url the form POSTs to) specifying 2 post paremeters (two field names on form - username and password likely).
2) This should allow you to access the .csv file through file_get_contents, fopen or cURL. Your choice.

As for the code, I have no idea :P

Read up on cURL.
Check out my portfolio, which entales all of my little projects and client work. Not interested in that? Well then take a glance at my blog and see if anything tickles your fancy!