Is it possible to disable browser caching with code? - php

I know that there are other posts about disabling caching. I've read all of them that I can find and am still having a problem, so please be kind and don't kick me for starting a new thread.
Here's the deal, I am working on a site that a landlord can use to list all of their properties. It's sort of like an MLS based site that a realtor would use.
The problem that I'm having wouldn't be a problem for me, but it will be for my client who isn't very bright (I can say that, she's a family member). Once a property is set up and all of the various pictures are uploaded there is an option to edit any of that data as well as delete any of the existing pictures. If you delete a picture, all works well but the browser caching makes it appear as if nothing happened. Hit F5 (in Firefox) to refresh the page and everything looks like it should.
The problem has to do with how I chose to name the photos that are uploaded. The photos are renamed using the property address info with the number of the picture appended. For example: 3505Cardinalpic1.jpg, 3505Cardinalpic2.jpg, 3505Cardinalpic3.jpg, etc. If I were to delete the first one, for example, the following pictures are renamed to keep the naming order intact. They would be come 3505Cardinalpic1.jpg, and 3505Cardinalpic2.jpg, for example. Both surviving pictures are the 2nd and 3rd pictures from the pre-existing sequence of 3.
When the page reloads after one picture is deleted, it loads the pictures from cache because the filename didn't change, only the source file itself.
I figure that I could fix this by rewriting my php that handles the pictures so that the file name is appended with a timestamp or something that would make each name still recognizable but unique but I want to make sure there is no easier way to do that before I go in there and futz with something that's working.
I'm intentionally not posting code because I don't think it's a code issue and the problem description is already long enough. If you'd like to see a section of my code, just ask.
I've tried this with no luck:
test php disabled caching
I've tried appending my url with a timestamp to make it unique and that didn't help either.
Thanks in advance for any advice.

To force the browser to not cache the file, link it with a changing parameter. If you do that :
<img src="3505Cardinalpic2.jpg?001"/>
and just after, that
<img src="3505Cardinalpic2.jpg?002"/>
the browser will reload the image because he is not sure this is the same. If you want never caching, you can put a timestamp as parameter.
But it's not good to disable caching, so maybe you can change the value only when there is a modification in your album ?

Related

Getting the page that loaded my image

I want to show some dynamic info on my image, but it needs to grab the HTML of the page that loaded my image.
There might me some security risks by that, but there should be another way since I've seen an image that does that on some forum.
The image that I'm rendering will be used on a site that I do not own, but can only add to the page, like make a post which will contain the image. The example I was pointing at was this where it shows 'Welcome to my profile, (user)'
Here's how it looks like on my pc,
Depending on client configuration it should be available in the Referer HTTP header
In PHP you can get at this with $_SERVER['HTTP_REFERER'];
Nvm it was much simpler than I thought. It looks like all he did was just simply connect to the referrer url, read the input stream, then go to that url again, read previous users, grab the latest one and just write that name onto the image.

What is the file path of the main page (home) of a Magento store?

I need to locate the file that manages the main page of my online store developed with Magento (which would be the index.html). I just need to change a link, and I've used Firebug shows that the file i need to edit is "misitioweb.com" (the main page) but the document itself does not appear in the ftp. The initial page consists of a bunch of XML, and PHP's PHTML. If someone wants to see the address page is http://peluches-cel.com and only want to change the destination URL of the link "Peluche del mes". I have used the help of Magento to show "Help template route" and I downloaded the 4 files that are more likely to manage that area of the page, but I can not find the part where specify the destination URL of the link. I have always worked with HTML or PHP separately (I have little experience with PHP) and I find it very difficult to understand how Magento builds each website. If someone could give me a little hint on how to achieve change that link would you do me very happy, it took a long time trying it on my own and looking online but can not find how to do any guestbook or forum that explains how to work well with Magento, in my language, there are hardly any documentation on Magento, so I decided to try my luck in this forum and I've read on several pages that involves many professionals in the e-commerce. Thanks in advance to all who devote their time to read my question.
I don't really understand what you want.
But if you want to change the base URL, you can do that by accessing database via phpMyAdmin, find the table core_config_data and change the URL in the web/unsecure/base_url and web/secure/base_url to what you want.
Not the url of the page, but the url of a link. Try clicking on "Peluche del mes" and see what comes out, gives access to http://www.peluches-cel.com/peluche-del-mes, I want access to http://www.peluches-cel.com/oso-tiziano-2col-40cm directly. The problem is NOT EXISTS peluches-cel.com/oso-tiziano-2col-40cm page on FTP, to be done in PHP there are different functions that are responsible for creating it at the time of the request I need to change the link to "Peluche del mes", if you see with firebug or any other source code analyzer, the source code of the page you will see that line 146 is managed that link, but I can not directly access the code ¿do you understand me? through an ftp client no such file or html as php magento works with the model view controller, that's my problem. Thank you again.

Making screenshot of the website with changes made by user

Is it possible to take a screenshot of the visible part of the website directly as it is seen by user (rendered by by the browser), including any changes made by user (e.g. moved divs, text typed in forms etc.)?
So you open a website, where you can make changes to its content. And there's a button (on the website of course), when you click it, the actual visible part of the website with all the changes you made is saved as an image and for example there goes a popup window where you can type in an email to send this image to, or something like that. Javascript, php, html5 or anything else? Old browsers and ie doesn't matter.
I've searched a lot for the answer, read lots of related articles, but I couldn't find the solution, cause what I need is not the script that would re-render the page like html2canvas, but capture the actual content displayed on the screen.
Any ideas and comments are much appreciated!
This is something that can be extremely tricky.
Essentially your only option of doing this in browser with no extensions or such is to try rendering HTML into the <canvas> tag.
There are several projects which do that, most reliable choices are noted in this SO question's answers: Render HTML in Canvas/WebGL
Note that none of the projects are 100% accurate, but a canvas can be rendered into an image and thus could be saved or emailed by the user like you asked.

Controller actions being called twice --- Php application

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.

PHP/JS: How to implement dynamic breadcrumbs? (multi-window/tab compatible)

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?

Categories