I am simply trying to increment the amount of page views per visit with CodeIgniter's active record. For some reason, the following code is incrementing twice. So it adds 2 page views per visit. What is strange is that this is used on another website that shares the same table and the same method code and it works properly on the other website. The views field is a simple int(11). I am only calling this method once in the controller, I thought maybe I had a duplicate but I do not.
function increment_video_view($video_pk) {
$this->db->where('video_pk', $video_pk);
$this->db->set('views', 'views+1', FALSE);
$this->db->update('videos');
}
Any ideas or help would be great! Thanks!
Try putting an echo (or log) statement inside the function to see if it actually gets called twice. Let us know if it only echo's once.
function increment_video_view($video_pk) {
echo "We in increment_video_view";
$this->db->where('video_pk', $video_pk);
$this->db->set('views', 'views+1', FALSE);
$this->db->update('videos');
}
Are you sure that the controller is executed only once?
This happens when you have a 404 link (image/css/favicon) in your HTML, or if you have a missing favicon.ico
Chrome looks for a favicon.ico even if you don't insert it in your HTML, and when it finds it missing, I think it calls another request.
Related
so I'm trying to use meta reload to update my website (using the code below) and I was wondering if it was possible to make it reload once after opening the page.
<meta http-equiv="refresh" content="3" >
Why, because looking at a website that refreshes every 3 seconds is really annoying to look at. If you can help, thank you.
#David's comment (original post)
To store values without files and within the webpage. I suggest you encrypt the data because it is visible in the developers console 'local storage'
function holdArray(array){
localStorage.setItem("holdArray", array);
return true;
}
function releaseArray(){
if(localStorage.hasOwnProperty('holdArray')){
return localStorage.getItem("holdArray");
}
}
Set data
holdArray(JSON.stringify(yourvariable));
Get data
let storage = releaseArray();
All I had to do to make it update once when the page was loaded was change index.html to index.php
Thank you with all the help you guys gave me, but this is all I ended up needing to do. I still very much appreciate the effort though.
I build a website based on one html file. I based the routing on HTML 5 API History. I made the addresses of the subpage with help from history.pushState and everything is ok, eg www.mypage.com/about.
The problem is in this when I try to refresh the subpage or how I will go directly to the address www.mypage.com/about. You can have an idea to call the function after going to www.mypage.com/about.
I tried to do something like that, but I get a 404 error
if (window.location.href.indexOf ("about")> -1) {
someAction (0);
}
However, if I added in the url address "?" or "#":
www.mypage.com/?about
Then this condition will be fulfilled and the function will be called.
The point of the HTML5 History API is to avoid refreshing the browser. If refreshing the browser is what you want to do, then just call window.location.reload():
if (window.location.href.indexOf ("about") >= 0) {
window.location.reload();
}
I am looking for help for the following scenario:
I have a website1.com. I would like website1.com to be like a presentation page. I want every person who has seen the page to be redirected automatically to website2.com.
Another way to look at it:
Lets say the page on website1.com contains information, which would be irrelevant for the person, who has already seen it, therefore I want them to be redirect from the page to website2.com cause then i don't loose the visitor, since I own both of those sites.
From the prespective of the visitor:
I land on a website, which I have not visited yet, website1.com. However, if I have already been to website1.com in the past ( cookie registers it ) , then i am redirected to website2.com
Hope how i broke it down is clear for everybody.
Thank you in advance for the help.
If you are using PHP, you could do it that way at the begining of your page:
<?php
if (!isset($_COOKIE['myCookie'])){
setcookie('myCookie', true, time() + (86400 * 30));
}
else{
header('Location: http://www.website2.com');
}
?>
If you are not using PHP, your serverside language surely have a way to set cookie and the logic will be the same. Hope it helped
I have a PHPBB forum along with PJAX.
PJAX works well with links however whenever I try use a .pjax function I get an error in firebug, claiming that .pjax is not defined?
Here is what works:
pjax.connect('wrap');
Here is what doesn't work:
$(document).pjax('a', '#pjax-container')
$.pjax.submit(event, '#pjax-container')
and anything that contains .pjax.
I have the pjax/pjax-standalone.min.js file included in my header.
Am I misunderstanding something here?
Thanks,
Peter
I am a noob facebook app developer and I would be very grateful for a little hand-holding getting started by professionals. I created a very simple app. It's only one file (index.php) and it has an html form that posts a value back to index.php to display. It worked before I added a "share to wall" request to the authentication. Now (I guess) there is a redirection before realoading the index.php, so it gets no $_POST value and it doesn't display the entered value. I would be very grateful if somebody would actually check out my app and its code and tell me how to fix it. (I think it's important to mention that it requests permission to post to the user's wall, but actually it doesn't post anything to the wall. I want to add that functionality later.) Here is the app:
https://apps.facebook.com/webszebb/
And here is the code (screenshot):
http://webszebb.hu/indexphp.png
Thanks.
For the sake of simplicity I'd suggest doing something like:
<html header stuff>
<?php
...snip...
if ($_REQUEST['do'] == 'whatever the action is, i.e: action="?foo" would be foo here') {
print('Your previous number was ' . $_POST['my_number']);
} else {
print('form');
}
?>
But to answer your question I'm assuming the $fb->api('/me') probably redirects you.