I am developing an web app with Laravel and I encountered this "strange" behavior. Some controller actions are called twice. I know so because on my logs I see (for one page refresh) two full sets of entries. My controller action starts like this:
public function action_edit($rid=-1) {
// Calc Input
$id = Input::get('id', $rid);
Log::TWICE("?? {$id} - {$rid}");
where $rid is the object id to edit as requested by the url, however if I get an id in my Input, then I use this id instead. So when I call my controller via a url like:
.../mycontroller/edit/1
I get TWO entries in my log file:
2013-02-07 00:49:15 TWICE - ?? 1 - 1
2013-02-07 00:49:16 TWICE - ?? img - img
The first one is the normal that I should see, however the second one I don't understand where it is coming from. I checked using the Chrome's developer tools (both network tab and console tab) but there is no sign of the second request!! I initially thought that I might try to use some resource with a relative url of img or ../img but I found no clue. Of course img is the name of my images folder on my template but there is nowhere in my code a relative url img by itself...
Do you have any suggestions regarding this issue? Where else in my code should I examine/check? What else could trigger the second call?
NOTE: I am using the following call at some point on my code but the referenced action is 'show' not 'edit'!!
Laravel\Routing\Controller::call($controller.'#show', ...
Thank you in advance!
Pan
This is probably the browser trying to request a Favicon.
Try with curl and you most likely won't see the request.
I had a similar problem, and the cause was a Trend Micro Firewall we were behind.
The datacenter was crawling every URL submitted, causing it to be hit twice.
This post has more information
http://community.trendmicro.com/t5/Worry-Free-Business-Security/WFBS-Trend-Micro-sending-our-data-from-an-IP-in-Tokyo/td-p/15600
I spoke to our web admin who said he would exclude the site from TrendMicros link site check
This is an old question, but I still see this at the top of the Google result when I search for solution, so I decided to add this answer after I finally find the problem.
The current answer that marked as correct is only partially correct: it is related to image, but it is not limited to Favicon.
Somehow all major browser (at least for IE, Firefox and Chrome) decide that when there is an empty link provided to whatever place that is supposed to be an image, they will make it the current URL. Some example of places that may cause problem:
<img src="">
<div class="background-image:url()"></div>
<link rel="icon" type="image/x-icon" href="">
Provide a link or simply remove the line will solve the problem.
Related
I am facing a small problem in my Facebook application. when I left single click any link, it will not work, but it will work perfectly when I tried to use right click and open in new window option. Please help me to find out the problem.
This is the URL, please check it http://apps.facebook.com/moviereviewforyou/
The code is:
<a href="{$url->reviewMovie($file.fkey)}">
<img src="{$url->img2($file.thumbnail)}" alt="{$file.ftitle}" width=100 height=100/>
</a>
Looks like you don’t have a (valid) SSL certificate – at least that’s the first thing my browser warns me about when I try to access your app (Facebook automatically redirects me to the HTTPS version of it’s page, because I have that option set in my account’s security settings).
And then you have your links href attributes set with a hard-coded "http://…" at the beginning, which is also not good when the user uses your app over HTTPS. Just use relative links instead of absolute URLs; or at least have them begin like "//example.com/…" (this lets the browser decide which protocol he has to use, based on the protocol used to request the page these links are embedded in).
The page you are referring to has the following in the <head> tag:
<noscript><meta http-equiv="X-Frame-Options" content="deny" /></noscript>
This is what denies showing the page in a frame. Remove this line, or set content to allow to let it show in the frame.
EDIT:
I noticed that the row I mentioned is in the header of FaceBook itself, not in yours. Are you referring to your page correctly? You shouldn't refer to the facebook page containing your page, but to your page directly.
I´m building a webpage that has a sort of catalog in it, which shows the current item and its description, and thumbnails for other items below it, if I click on a thumbnail of a different item, I have some script to change the description and the big image to the desired item. The problem is that I want this to reflect in the URL so the user could send the URL as a link to other to show the desired item. But I havent found a way to change the URL without having to reload the page, and for aesthethics, I dont want to reload the page.
Any ideas how to do this?
The solution is to use location.hash. Also, to implement it correctly, you might want to read this article from Google: Making AJAX Applications Crawlable
There is no reliable (cross browser) way to change the URL in the address bar without reloading the page - the very act of changing window.location.href (which I imagine is what your trying to do) tells the browser to reload the page (even window.location.href = window.location.href; will do it in some browsers).
I think you would have to put a [link to this page] element on the page and change that instead - you can easily populate it with the current URL either at the server side or using a window.onload function and manipulate it in the same way as you have been doing using element.value or element.innerHTML (depending on what type of element you choose to contain the link).
You can do it with hashes (see the window.location.hash property) but this can be messy programmatically.
The usual, currently-broadly-compatible way is to use a hash, e.g.:
http://myniftystore.com/catalog#11321R-red-shirt
then
http://myniftystore.com/catalog#11321B-blue-shirt
then
http://myniftystore.com/catalog#95748B-blue-slacks
...as you navigate items. You can change the hash on the page by assigning to the location.hash property, without reloading. This requires that you use some client-side script in the first place to figure out what to show when the user first goes to the URL (by examining the location.hash).
Google has a proposal out for how to make these things crawlable. Personally, I think they've really messed it up by requiring that weird hashtag (#!xyz rather than just #xyz), but if it's me or Google, I think I know who'll win. :-)
Coming down the pike there's the whole history API, but support isn't very thick on the ground yet (particularly not — cough — from certain vendors).
I am currently investigating a double request problem on my site. Not all the time, but sometimes, a requested page will in fact load twice...which is not a problem really until it is on a page with PHP that inserts stuff into my db on request (my tracking script).
I have read that an empty src in an image tag, and an empty url() in a css background could potentially cause the page to be requested twice.
However, I can't find any problems with those.
Is there anything else that could be causing something like this?
ANSWER FOR MY SITUATION
After some extensive research, it turns out that in my case specifically, the second request has been coming from the user agent "Mediapartner-Google". I began to notice that on pages that serve an Adsense ad, I could expect a secondary visit from this crawler within seconds after I visit the page myself.
This doesn't seem to be happening on pages without Adsense ads.
I am going to mark an answer below, because it seems like for most situations, those are the correct things to check.
I have sat beside people whom I would swear knew better than this, and watch aghast as they double-clicked on every hyperlink in our app.
Didn't take long to figure out why they were experiencing double the page load time of everyone else...
Things like this certainly tend to give one pause when implementing pages that change the backend state. A lot of people put sequence numbers in hidden form elements so the backend can detect a double-submit.
The causes I've seen before:
Missing stylesheet or image
Web developer addon for Chrome/Firefox sometimes requests things twice if you're validating HTML etc.
Browser inconsistency
Sometimes it's just too difficult to track down the root cause of a double request.
Either way, you should NOT be changing database state (or session state) through a GET request. The only SQL query you should be running without postdata is SELECT. All updates and inserts should be done using forms, even if the form consists only of a submit button.
src="" in certain elements on certain browsers (such as <img src="" />) can request the current page again.
404's are a prime source for a request seemingly being requested twice. Check your CSS, JS and image sources are all correct.
We had a very strange behaviour in our CMS where an iframe in a jQuery dialog lightbox made a doubled database insert.
After hours of debugging and loud WTFs we nailed it down. the dialog close method was setting the focus to the iframe of the dialog before destroying it and caused a reload of the iframe url!
I have seen this countless times. The internet is full of strange people who keep double-clicking on everything they come across.
You can stop this in you web site by attaching a global double-click event listener to every anchor tag ( tags).
For example, if you have jQuery installed, you can do the following:
jQuery('a').on('dblclick', function(e) { e.preventDefault(); });
This is just an example of course. You can achieve the same result using vanilla Javascript.
That should silently ignore the double click action.
In case they are fast clicking twice instead of double clicking, then you can use can throttle the click handle on all the links in the page to ensure that they cannot be clicked more than once within say ... 3 seconds.
I'm new around so if I'm missing some info or something, please let me know and I'll provide it. I've already looked for informationg regarding this error, but I haven't found anything relevant yet.
So, here's the deal.. Some of my controllers actions are being called twice, and I've just noticed that when I was wondering why was I sending SOME mails twice (the application I've got has an email client incorporated).. and only then after logging what was I doing I noticed the controller gets called twice... By the way, this only happens when I called the action from a link outside the application or by typing the url.
If I'm not making myself clear or I'm missing something, please do post here anyway so I can add more info..
Thanks in advance!
Aggregating possible answers from other sources as per my comment:
<img src="" /> and relatives.
If you have places where you generate the src attribute of the img tag, make sure it isn't empty in any freak cases; a handful of browsers take the empty src as a prompt to load the page again. 1, 2, 3
The same is true for an empty favicon, javascript or css href - generally anything where you're asking the browser to fetch an external resource, but no url is supplied, even in css1.
The phenomenom is perhaps a more understandable if you consider, for example, where you're sending form data when you do <form action=""> (or even just <form>) - namely the same page.
.htaccess shenanigans.
Check your rewrite rule(s): Are you making the server take a roundtrip to your script for any static content (e.g. favicon1)? Do non-existent files trigger a call to your script, and is an external resource link pointing to one (e.g. an ancient css stylesheet that was finally deleted from the filesystem but someone forgot to remove it from the HTML source)?
Browser-based debuggers.
Some browser-based debuggers, e.g. firebug1, will send a second request to the page depending on circumstances, to gather data that wasn't natively supplied to them by the browser itself. Make sure you're not getting that.
See if any of those help you.
For me, having Firebug open was causing the page to be called twice.
Without seeing the actual application code, I'm left to simply guess - however, I know of at least one semi-famous bug in this arena, see http://blog.codekills.net/archives/27-Fun-with-Firefox-Jitters.html for the details - basically, it happens when a <tr> has an onclick handler and an <a> inside that goes to the same URL...and even if this isn't what your app does, perhaps you can gain some insight from seeing how they went about debugging the problem.
After hours of debugging, my issue was a dynamically set background-image css tag. If there was no image - background-image:url() - a second request would be made back to the controller once the page was loaded.
Just in-case anyone else is doing the same.
My particular version of the problem and fix
submitting this form worked on a production server, but not "localhost"
For Firefox: form worked in both places. For Chrome: only worked on production server
setting breakpoints in my problem controller confirmed it was getting called multiple times (duh) and CSRF protection on that form got gibbered up as a result.
Then I found this thread: http://ellislab.com/forums/viewthread/210318/
My solution involved the favicon. The src attribute wasn't quite right. I did have a favicon in the root directory and it loaded on the hompage but not others (didn't notice that for a while). Anyways, providing an absolute path to the favicon solved it
Don't really know if you MUST have a favicon, but like mentioned above, make sure any resources you pull in (img/js/css) are properly referenced so as to avoid a browser retrying to request a page
On my Code Igniter View, I have a Form. THe form has a Post method calling url of controllerA. On clicking Add button in the form, I was calling a Javascript function that validates email ID. After validating email in .js, I was posting some data using $.post(url...) to the controllerA for database insertion. The insert was happening twice.
It turned out that in the $.post(url) I was calling controllerA url.
When I commented that $.post, database insert worked fine.
I'm trying to understand code that I bought so I can modify it.
In the index.php there are picture links:
<a href="test10,10"><img title="" border=1
src="makethumb.php?pic=product_images/test101.jpg&w=121&sq=N" / ></a>
I don't understand the href since it is not pointing to a page. test10 is an id of a picture. I assumed it was going back to the index.php and the code would extract the test10,10 from the url, but it's not. I know that because I put in trace code as the first line.
The question is, where is the link going to?
I know it that it somewhere in the process it executes a page called profile.php, but nowhere in the source code (doing a global search) is there an explicit call to profile.php.
As a related question, is there a way to profile the code to see what pages it's calling without using xdebug, which for the life of me I can't get working after many hours of trying every suggestion I found here and else where. (I'm using xampp)
The flow is: you enter the site www.site.com/final/index.php. which displays pictures with the link as above. When you click on the picture with an id of test10 it takes you to www.site.com/final/test10,1
thanks
The question is, where is the link going to?
Under normal circumstances, a request to
www.yourdomain.com/current_directory/test10,10
is made.
Usually, Apache will try to find a file of that name, and fail.
If the behaviour you get is different, then there is probably a mod_rewrite rule set up somewhere. Look for .htaccess files (note, files in parent directories affect all children) and check the httpd.conf, httpd-vhosts.conf and other log files for any RewriteRule settings.