I designed a site for a customer where members log in to a member's area to download files. I used a PHP script (called pageprotect) to manage the users. The admin area includes a log which monitors when users login, but my customer wants to know when a user actually tries to download a file.
Is there some PHP code I could add that will email my customer whenever one of her users clicks to download?
Thanks for your help.
Vito
jtrovato
11-27-2002, 12:02 PM
Well you could have it link to a different page instead of the file and on that page it will write to the database and then download atuomatically. It's something you should write.
Thanks, jtrovato. Although, that would mean having to set up a MySQL db, no? Is there not some simple code that I can insert into the existing HTML page to fire off an email whenever the zip file link is clicked?
Vito
jtrovato
11-27-2002, 12:29 PM
well you would need a way store the data. I guess you could use a text file and increment it accordingly. If you have an extra MySQL database, you should use it. It will make life easier.
John
Sorry to belabor this, but I don't understand. Why would I need to store the data? Right now, her log records when a user logs on. So if I can just get the act of clicking on a download link to trigger an email to her, that's all she'd need. The email doesn't have to state WHO is attempting a download. Just something to tell her that SOMEONE has clicked on the link.
She doesn't have alot of members, so it would be fairly easy to match up the date/time of the email with the user's record in her existing log.
h2oski
11-27-2002, 09:26 PM
something like this?
<?php
//what ever contents you like. if you already have a username you could throw
// it in here so you know who is downloading
$contents = 'someone has just downloaded a zip file';
mail("admin@domain.com", "download", $contents);
//had to space out the http for vBulletin
header("Location:h t t p://domain.com/path/to/file.zip");
?>
Cool, h2oski, that looks great. So if I put the following into an html page:
<?php
$contents = 'someone has just downloaded a zip file';
mail("admin@domain.com", "download", $contents);
//had to space out the http for vBulletin
header("Location:h t t p://domain.com/path/to/file.zip");
?>
-replacing the email address
-showing the actual path to the zip file
then I will receive an email telling me whenever someone attempts to download that file?
Vito
Damn, didn't work. Here's the code for a test page I put up:
<html>
<head>
<title>Viola test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a href="/whm-signup.zip">Download</a>
<?php
$contents = 'someone has just downloaded a zip file';
mail("info@demodemo.com", "download", $contents);
header("Location:h t t p://www.demodemo.com/whm-signup.zip");
?>
</body>
</html>
The only thing that is different in my actual code is that I don't have spaces in h t t p. What am I missing? Should I be replacing "download" with something else?
Hmm. What I also notice is that when I point my browser to the test page on my site, if I look at source code, I see the actual php code. That's nor supposed to happen, is it?
Also, do I not need an "if" statement in there somewhere? (Man, am I ever pathetic when it comes to understanding PHP)...
Vito
h2oski
11-28-2002, 09:57 PM
sorry, I should have been more clear in what to do with that code.
first, php files need to have the extension .php instead of .html or .htm
so upload that code just as it is without any html added in and name it something.php
now on your html page where you display the link to the download you are actually going to link to something.php
when they click on that the email will fire, any the user will be redirected to the .zip
PERFECT!!!!
Thanks so much, h2oski! Worked like a charm. :)
Vito