can html link to an MP3 also invoke php?, when clicked, can anchor do both php and give the file? |
can html link to an MP3 also invoke php?, when clicked, can anchor do both php and give the file? |
freddie tane |
Mar 15 2007, 06:35 PM
Post
#1
|
Group: Members Posts: 4 Joined: 15-March 07 Member No.: 2,211 |
Greetings forum! I hope I'm in the right area
to find out about programming php on my website. I have a Linux / PHP / MySQL virtual hosted server, so I can't change much about the configurations. Would you have any suggestions or guidance on how to do this: On an html page, visitors click a hyperlink to an MP3 file <a href="audio/PurpleLizard4.mp3">Tane Tunes:</a> And in addition to the click initiating the file being delivered to the visitor, I would like php to run a procedure to record the fact of 1 click on the MP3 file, and if possible, various info about visitor (browser, ip, etc. into MySQL). Is there more syntax to the <a></a> tag that allows me to call a php function in it? Or is there php functionality that would behave similarly, maybe like this pseudo-code: <?php <a href="audio/PurpleLizard4.mp3">Tane Tunes:</a> php_log_click(PurpleLizard4.mp3) ; ?> Thanks very much for any suggestions! - f |
Darin McGrew |
Mar 15 2007, 08:26 PM
Post
#2
|
WDG Member Group: Root Admin Posts: 8,365 Joined: 4-August 06 From: Mountain View, CA Member No.: 3 |
Check with your hosting provider to see how you can access your server logs. From your server logs, you should be able to determine how many times each URL has been accessed.
|
pandy |
Mar 15 2007, 08:41 PM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,733 Joined: 9-August 06 Member No.: 6 |
If you still want to do it, you have to do it the other way around. You link to a script that a) increments a counter and b) redirects the browser to the download.
|
Brian Chandler |
Mar 16 2007, 12:17 AM
Post
#4
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
QUOTE If you still want to do it, you have to do it the other way around. You link to a script that a) increments a counter and b) redirects the browser to the download. Uh, no, I don't think you have to do this. You set up Apache to pass .mp3 files through the php interpreter, and you write a php script called soppysong.mp3 that increments the counter, then sends the correct headers for an mp3 and simply echoes the ("real") mp3 file. No redirect necessary. If you want to be more open about it, use a script called mp3.php, so mp3.php?id=soppysong gets the song and echoes it. Compare the following jpeg file: http://imaginatorium.org/graphics/iromap.php?x=75&y=71 (I know M$'s pseudo-browser offering sometimes screws up by relying on the filename instead of the headers, so I'd be grateful for feedback if this gives problems.) Incidentally, I do not think server logs are the answer to everything: it may be much easier to keep the particular record you want directly. |
Brian Chandler |
Mar 16 2007, 12:22 AM
Post
#5
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
QUOTE Or is there php functionality that would behave similarly, maybe like this pseudo-code: <?php <a href="audio/PurpleLizard4.mp3">Tane Tunes:</a> php_log_click(PurpleLizard4.mp3) ; ?> Can you see why this couldn't possibly be what you need? Writing something immediately after the <a href=...>...</a> stuff means that the php call occurs each time the **page with the link** is sent out. But you want something that happens each time the link is clicked in a browser, i.e. each time the **mp3 file** gets sent. So obviously any php code has to be part of the mp3 file, not the page with the link. HTH |
Peter1968 |
Mar 16 2007, 02:06 AM
Post
#6
|
Serious Coder Group: Members Posts: 448 Joined: 23-September 06 Member No.: 213 |
Alterantive, have a look at one of the downloads modules of any given GPLed PHP-based CMS and see how the download counting is done.
|
Effovex |
Mar 16 2007, 02:42 AM
Post
#7
|
Serious Coder Group: Members Posts: 251 Joined: 6-January 07 From: Sherbrooke, Qc, Canada Member No.: 1,477 |
Brian's on the money, actually. That's exactly how it's done.
|
freddie tane |
Mar 16 2007, 09:12 AM
Post
#8
|
Group: Members Posts: 4 Joined: 15-March 07 Member No.: 2,211 |
Quite a diversity of suggestions - greatly appreciate the input! Glad I found this forum!
I'm not inclined to go with server logs, but thanks. I think I get the approach suggested by Brian Chandler regarding configuring Apache: > Uh, no, I don't think you have to do this. You set up Apache to pass .mp3 files through the php interpreter, and you write a php script called soppysong.mp3 that increments the counter, then sends the correct headers for an mp3 and simply echoes the ("real") mp3 file. No redirect necessary. But - I'm on a hosted server (godaddy.com) - I'll have to check on whether I have the ability to do any "set up" to have Apache pass .mp3 files through php interp. Further to pandy's suggestion: > If you still want to do it, you have to do it the other way around. You link to a script that a) increments a counter and b) redirects the browser to the download. My novice-itude is showing - but what would the redirect approach look like in php? Thanks again! - f |
Brian Chandler |
Mar 16 2007, 10:00 AM
Post
#9
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
QUOTE But - I'm on a hosted server (godaddy.com) - I'll have to check on whether I have the ability to do any "set up" to have Apache pass .mp3 files through php interp. This may be the killer. What _exactly_ does "hosted server" mean? I use pair.com, who I recommend wholeheartedly; their cheapest account is around $5 a month, and I'm fairly sure this now includes php, mysql etc. I am using a _shared_ server - I understand what this means: the server, an ordinary physical computer, runs Apache to serve a number (100s) of websites, including mine. Obviously I can't change the basic configuration of Apache, but I can use .htaccess to set things for my webspace, and basically run whatever I want. Is Godaddy like that? |
Christian J |
Mar 16 2007, 12:53 PM
Post
#10
|
. Group: WDG Moderators Posts: 9,661 Joined: 10-August 06 Member No.: 7 |
I use pair.com, who I recommend wholeheartedly; their cheapest account is around $5 a month, and I'm fairly sure this now includes php, mysql etc. Pair might be good but they're also quite expensive. According to http://pair.com/services/compare.html it seems you must pay from $17.95 a month for PHP and MySQL. |
freddie tane |
Mar 16 2007, 01:56 PM
Post
#11
|
Group: Members Posts: 4 Joined: 15-March 07 Member No.: 2,211 |
Some more info on my hosted website+database, I have found that
there is an .htaccess file in the root of my web directory. and I can edit it. It has these entries, what kind of entry would set .mp3 files to pass through ? # -FrontPage- IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti* <Limit GET POST> order deny,allow deny from all allow from all </Limit> <Limit PUT DELETE> order deny,allow deny from all </Limit> AuthName www.tanetunes.com AuthUserFile /var/chroot/home/content/f/t/f/ftftp/html/_vti_pvt/service.pwd AuthGroupFile /var/chroot/home/content/f/t/f/ftftp/html/_vti_pvt/service.grp Thanks again! |
Peter1968 |
Mar 16 2007, 06:42 PM
Post
#12
|
Serious Coder Group: Members Posts: 448 Joined: 23-September 06 Member No.: 213 |
I still think you'd need to adapt one of the download scripts a CMS supplies for your needs. The download module that PostNuke (or similar) uses allows you to give a description of the file, its size, upload date, and most importantly for you, the amount of times downloaded. Also, yo uand visitors can "rate" the file.
Excellent example of one of these scripts in action I'm sure with a bit of PHP savvy (which I don't have) the script could be adapted to record various things about the browser or user agent that downloaded it, using PHP variables like HTTP_HOST, REMOTE_ADDR etc. |
freddie tane |
Mar 28 2007, 11:31 AM
Post
#13
|
Group: Members Posts: 4 Joined: 15-March 07 Member No.: 2,211 |
Sorry, but I'm still stuck on this.
So far I've researched and understand how to re-direct in HTML. However, understandably, the php code never executes: <html> <head> <META HTTP-EQUIV="Refresh" content="5; URL=audio/PurpleLizard4.mp3"> </head> </html> <? Echo "Hello World, from PHP!" /?> I like the idea of Brian Chandler regarding Apache pass through, but am not sure how to implement in .htaccess (entries in my .htaccess were shown previously). Suggestions were: 1 php script called soppysong.mp3 that is really php, and then sends the correct headers for mp3 2 script called mp3.php, invoked as mp3.php?id=soppysong gets the song and echoes it. 3 copy mechanisms from an existing CMS (Content Management System?) counter script Concepts unknown: send the correct headers echo the real mp3 file I wanted to read the code of iromap.php in the imaginatorium, but, of course, cannot. Any help appreciated. - ft |
Christian J |
Mar 28 2007, 04:11 PM
Post
#14
|
. Group: WDG Moderators Posts: 9,661 Joined: 10-August 06 Member No.: 7 |
CODE <html> <head> <META HTTP-EQUIV="Refresh" content="5; URL=audio/PurpleLizard4.mp3"> </head> </html> Why the closing </html> tag? If you want more content on the page it should be inside BODY, in turn inside HTML. CODE <? Echo "Hello World, from PHP!" Just in case: if you'd use more than one PHP instruction they'd have to be separated with semi-colons, see http://se2.php.net/manual/en/language.basi...-separation.php CODE /?> You shouldn't use a slash in the ending PHP tag, see http://se2.php.net/manual/en/language.basic-syntax.php Webhosts may disable error reporting, otherwise the above should result in an error. You might turn error reporting back on with http://se2.php.net/error-reporting |
Lo-Fi Version | Time is now: 27th April 2024 - 12:51 PM |