just yesterday i finished one site, which provides video watching.
but now i need to show the number of views of each film. i never wrote such thing, so i don't know what to do.
maybe i must add one field in mysql database, and increase it every time the video opened?
but i use flash player, and i can't wrote script onclick of player.
so, could you give me an idea...
thanks
The best way is probably going to be to just parse your webserver's log and look for when Flash requests the video stream (nightly cron job). I'm guessing you are using a pre-existing Flash video player, where you may not have the ability to modify the Flash to push a server request to update the view count when PLAY is clicked, nor do I recommend it because you might switch to another player or to HTML5 streaming.
As already suggest I also agree, just add a "view_count" to your "video" table and increment it, you can do it in one step with (no need to retrieve, add and update)
UPDATE video SET view_count = view_count + 1
Also keep in mind, if you incrimenting your video count upon loading the video page, make sure to exclude page views from search bots (ex: google) because half or more of your view counts could end up being search bots. You can find a list of search bot browser strings, so you know what to look for here.
I'd create a table called video_views or something, have it contain the id of the video being viewed. I'd then use Flash's ExternalInterface functionality to call a JavaScript function which would, in turn, hit a remote URL via ajax to add a new record to video_views.
I've done this a few times in the past and it's always worked well. You could also just maintain a view_count value in your videos table and increment that each time a video is viewed.
[Edit]
One argument in favor of tracking each individual view would be the ability to add a timestamp to each record and gain further insight into things like peak traffic times.
Another way to go about it is to pass the web (Apache) Logs through a script real time by using the CustomLog directive as such
CustomLog |/var/www/view_count.php common
This would allow for real time statistics. Not sure if you need those or not.
fetch like below:
$viewd=$results['viewd'];
$viewd+=1;
mysql_query("update user set viewd = '$viewd' where id='1'");
Related
What I am trying to do is give companies an option to show their ads on my website, like how Facebook does. I have a user based website, so there are many different pages.
If I have to guess, it would go something like this.
Step 1. Company creates an Ad(with different payment options).
Step 2. The Ad is added to a mysql table.
Step 3. The Ads are shown across the website, depending on the algorithm.
Now I would need to know a more detail way of doing it. Are there any good resources I can study?
Well, you have multiple options. The easiest is to just use an existing ad-company like Google AdWords. Just just create an account there, embed their code in your site and you're finished.
The point is that creating your own ad-engine brings several problems:
You have to write the engine, including payment options, click tracking etc
and care about legal problems and contracts (a company may sue you for not displaying ads enough, caused by bug or misinterpretation etc)
Also you need to find someone who advertises at your site
AdBlocker
It's not impossible and embedding a static image won't bring to much problems, but for totally automating the engine you'll have to worry about all those problems, especially the legal ones. If you still want do this, look at 4chan's AdEngine:
Let the advertiser upload an image and store it on your server, save the click or view count left in the db.
When a site with ads is loaded, query the db for ads where count_left > 0 (order by random is an option, as it usually balances at many queries) and display the corresponding image. If your site has different categories, you may want to add a tag-clause or something. Also, set the view count down by one. If you intend to use click count, let the img's link point on your website and subtract the clickcount, but watch out that it isn't called multiple times by a single client to damage your customers (per-session or per-ip lock).
Hope this helps; I'd recommend you AdWords as it saves a lot of trouble and work.
I'm not even 100% sure how to ask this question, but I will try my best...
So, take youtube. You've got this:
URL/watch?v=Video_URL_Here
While on this video, you decide to click a video in the related on the right-side.
While doing that, the page refreshes, and instantly jumps to that video.
I have the basic concept down:
> Create a variable.
$var;
> User: *Clicks First Video*
$var = Video_One; // Pulls from mySQL-DB
> Open a new page (ex: URL/watch?v=Video_ONE)
PHP: >Creates a whole new page for the video.<
> User: *clicks new video*
$var = Video_Two;
> Open a new page (ex: URL/watch?v=Video_TWO)
PHP: >Working more magic.<
However, I'm having a hard time actually doing this.
Could anyone point me in the right direction or explain how it works?
It would be very appreciated.
The way YouTube works is using $_GET variables. That's what the ?v= is. It's taking in the v variable and checking the database for a video with that video id. The way they create the new page is by fetching each of the values corresponding to the id that was passed in the url, then putting that data in each of the page sections.
Let me answer with a very general and oversimplified example
actually, more than having a unique "$var" that changes every time you click on a video (on your example), it is more like the page already knows where to go for each link (or click), that is, every video already has a link associated, with the corresponding url.
all this is done BEFORE the page loads. (there are ways to make it after, but that is another matter).
Just to give a quick example (it may not be exactly how youtube works, it is just an example)
Lets say you store each videos name, description, rating, etc on a database table.
e.g.
video1name, url1, description1, etc1
video2name, url2, description2, etc2
video3name, url3, description3, etc3
also assume each video has already related videos stored somewhere (the videos which would show on the right side) (imagine they are in the same table, each video having their own "related videos" associated.
so, when putting the page together, via PHP (in this case), what the code does is, read the data from the database, so it will know what it will "paint", at that point, it stores such data in variables, and using those vairables, it is ready to build the page, using such data.
imagine you say "i need 5 videos here, those videos are this, this other .... etc"
so php will read those 5 videos info form the database, AND knowing their data, it already "knows" what will the specific url for each video will be.
it only has to build links for each video, each having it's speciffic url.
e.g.
[some html]
...
<a href="myvid1url" > ...</a>
<a href="myvid2url" > ...</a>
<a href="myvid2url" > ...</a>
...
[the rest of html]
the only thing php is doing, is creating HTML dynamically, based on that data, and once it finishes, it sends it to the browser, which only has to "paint" plain html, all of which is already filled with the particular urls, names, etc for each part.
This is a VERY generalized example, but i hope you get the idea.
The most important part is to understand that most of the time, pages are already "built" before being displayed, once loaded, they already "know" what to do when you click somewhere, etc.
Of course, you can add interactive functionality, using javascript, ajax, etc, and that MAY change the page already loaded, but that is another concept.
I think you should first tell us what your experience with programming is, or if you have only made plain simple htmls pages or anything, so we could give you better advice.
have fun!
You could use JQuery and have the second video load in a frame, iframe, div, table, new window, etc (depending on the data source, of course)
External sources (depending)
jQuery loading external page (cross domain) into Div element
Local content sources
Load HTML page dynamically into div with jQuery
For external data loading you could get all creative and run a curl to save the data locally, parse it for what you need and then serve that locally
Hey there, I'm trying to create a way of when a link is clicked in my flash movie (that is embedded in html) its counted and added to a "database" so I can keep track of the hits. Bearing in mind i've got 23 different links so I need a separate count for all 23.
Thanks - Caius
you have a few options, but frankly, I don't see how JQuery fits in.
Option 1: Use third party analytics software like Google Ananlytics
You can call the GA hooks in your swf to trigger specific content views, or you can use javascript to update the browsers anchor location ( http://mysite.com#link1, http://mysite.com#link2, etc...)
Option 2: Roll your own simple tracker
When the user clicks on a trackable item in your swf, call a script on your server that updates your database. a simple PHP script could handle that.
cheers.
We're using the Google CSE (Custom Search Engine) paid service to index content on our website. The site is built of mostly PHP pages that are assembled with include files, but there are some dynamic pages that pull info from a database into a single page template (new releases for example). The issue we have is I can set an expire date on the content in the database so say "id=2" will bring up a "This content is expired" notice. However, if ID 2 had an uploaded PDF attached to it, the PDF file remains in the search index.
I know I could write a cleanup script and have cron run it that looks at the db, finds expired content, checks to see if any uploaded files were attached and either renames or removes them, but there has to be a better solution (I hope).
Please let me know if you have encountered this in the past, and what you suggest.
Thanks,
D.
There's unfortunately no way to give you a straight answer at this time: we have no knowledge of how your PDFs are "attached" to your pages or how your DB is structured.
The best solution would be to create a robots.txt file that blocks the URLs for the particular PDF files that you want to remove. Google will drop them from the index on its next pass (usually in about an hour).
http://www.robotstxt.org/
What we ended up doing was tying a check script to the upload script that once it completed the current upload, old files were "unlinked" and the DB records were deleted.
For us, this works because it's kind of an "add one/remove one" situation where we want a set number of of items to appear in a rolling order.
I'm working on a site where we need "dynamic" breadcrumb generation.
Pages within this application are not specific children of the other, so when the user is browsing one of them, I can't simply retrace steps back up.
I could have the following breadcrumbs-like lists: (updated)
* inbox > message > user profile
* search results > user profile
* search results > user profile > new message
( FYI; there will be a few dedicated parent pages that will reset the whole stack. Also there will be a check that prevents recursion. )
So... To accomplish this, I have to remember where the user has been, and in what order. I reckon the most elegant and reliable way to do is, is write a mechanism that remembers the user's history in the session.
If I do that though, the whole thing will break when a user opens a new browser window or tab.
To fix that, I could store this data in the querystring. Though different browsers/proxies have different limits of data that can be transferred that way. So, one day, this will probably break as well.
Does anyone have an idea on how to implement this?
Or;
Does anyone know how to reliably identify different browsers windows?
(I'd rather not rely on javascript for this, unless it's my only workable option. I use dojo toolkit for the frontend)
thanks in advance!
On HTML5 compatible browsers I would save these on the local storage.
You can detect a new tab open like this:
on page load set a cookie by javascript
use the onbeforeunload event to clear the cookie
When the visitor will open your site, it will set a cookie eg session=1, if they click on a new link on your site, when they leave the site the cookie will be eg session=0 but as soon as they arrive again on your site it will be session=1.
When the visitor will open a new tab, it will encounter a session=1 so probably will do that session=2. You got the point?
window.name survives a new document load. So you can write a history string to window.name and then read it back from the next page, or use a generated name as a key for storing window-specific cookies/sessions.
I don't think this is a good idea though. “Breadcrumbs” are traditionally a hierarchical navigation device, not a history list. The browser already provides a perfectly good history list on the back/forward buttons that it is not useful to reproduce on the page; presenting an on-page history list, especially in a format that is normally a hierarchical place marker, is more likely to confuse users than to be of any help.
I asked a similar question a few months ago. The top answer - which I will am planning to go with - suggested building a path, and parsing that using a combination of mod_rewrite and PHP:
www.mysite.com/inbox/message/user_profile/12345/new_message
Up to a certain point (the request URL should never grow larger than 1024 bytes), that can be quite a good solution. An additional advantage is that the breadcrumb path can even survive sessions, and works in links forwarded to others (if that is desirable in your scenario).
Another thing, looking at your examples, I can't really see the need to reset the history when the user opens a new page, or to take different browser windows into consideration at all. There is a logical hierarchy (not a history) and why should the system start changing then hierarchy just because I choose to open the new message editor in a new tab?