PHP session_cache_limiter not working in Safari? - php

I've been trying to correctly manage sessions throughout the online ordering system I'm writing using PHP. I've got it functioning the way I intended and I allows users to hit the "back" button mid-process, without screwing up the database.
The only thing I do still want, is to prevent the "back" button being used on (or after) the final "All done" screen.
In step 3 (Confirm and proceed) and step 4 (All done), I've included the lines:
session_cache_limiter('nocache');
session_start();
This works perfectly in IE - you see the page confirming your order, but you get a warning if you try to hit "back". The same applies if you navigate on from the site - you can't see the final step.
The same site doesn't seem to work in Safari (5.1.2). I can hit "back" and see all the content that was displayed (it's getting it from a local cache, and not the server).
The site doesn't accept repeated input, so it's not a massive problem, but it's not the functionality I wanted. Does anyone know how to make this work in Safari?

I don't think the problem is the code, but the browser behaviour.
In Safari, when you press the back button, it just bring you to the same page you were before, just like you opened the new page in another tab and then closed it, even if you set the cache to ‘no-cache’. In Internet Explorer, on the contrary, when you press back, it takes you to the previous page by pointing to its url and loading it again.
Reading here and there, it seems that there's no way to avoid this behaviour, apart from a little trick, which should force the browser to reload the page when you press back: Preventing cache on back-button in Safari 5.

Related

set my website as homepage for android device browser using PHP code

I need to define a button on top of my website which when a user open my website with android device and click on that button, my website set as his homepage on his android device browser. I need to do this with PHP or javaScript if possible.
I dont think this is possible. This might lead to security issues. If this could have been possible, everybody would want to have a button like this. Lets take a scenario.
I open a page and click on the button.
The button sets a particular (unknown) page as the default homepage.
Next time when i open the browser, that (unknown) page does something malicious. Like an infinite loop of alert.
I would have to uninstall the browser to get this sorted.
However for desktop broswers, this might be possible as there are ways to fix such issues. Like opening in safe mode and changing the homepage.
P.S: You cannot do this with PHP in anyway.

Lost sessionvariables in firefox

I have a pretty strage problem im dealing with.
Lost sessionvariables in firefox.
Im using wordpress and have a subpage that causes the loss.
More specific:
In wordpress there exists a page called My pages (Original page names are in swedish, translated for convinience)
Under this page i have a few subpages. Among these are a page called Create test. There is nothing special about this page, for now only contains the phrase "hello world". If I enter any page other that this, it works.
But this particular page just seems to clear my session variables (wich I use to store login info)
I tried deleting the page in question in the effort to remake it.
While it was deleted I tried navigating around on the page.
Create test was the last item in the subnavigation menu, and now when its gone, the same thing happens on the last menuitem (now Account settings). This leave me to believe its something with the menu.
Even more strange, after recreating Create test, so that this page is now the last item. Still it's Account settings that is the page with the resetting of sessionvars...
I have through echo determined that the session id stays the same, just the variables that get unset.
I have unset($_SESSION['id']); at only one place, and this code is NOT run.
The problem just baffles me and I have no idea why this particular pages does this.
It may be totally unrelated, but we had problem with Firefox and sessions on certain pages in the past. It happened most of the times while developing and therefore refreshing a particular page, have you tried clearing your browser cookies which is where session is stored?
As an addition:
Check that you assign sessions before you write anything to the response stream.
Also we had similar problems with sessions set in a pages that were doing a redirection (i.e. a login page that if successful would set the session and redirect to the another page.)
I'm not sure about PHP but in .NET that can be overcome by explicitly setting not to terminate the response so that all headers are written to the response stream.
Fixed now, actually have no idea what I did. but I've change some html but mostly CSS.
So there is a strong posibility it was CSS-related.

PHP Print statement works only in Firefox

The site is built in drupal. The following code calls some data for the page:
<span class="bold caps">Length: </span><?php print $node->field_length[0]['view'];?>
The right information shows up when viewing the page in Firefox but that's it. Chrome, IE & Safari are all missing the info. The rendered HTML is fine but for the lack of the right data coming through.
Here is a link to the page in question
Any ideas?
PHP doesn't randomly decide to NOT output something based on the browser that's requesting the page. The choice of browser can NOT affect how PHP runs a piece of code. However, the choice of browser CAN affect the data that is sent to the script as input, which can affect how the script runs.
So check what the differences are between what FF sends to your script against what the other browsers are sending.
This is a server-side thing, not a client side. It SHOULD show in all browsers
1) Check the page source of Firefox and Opera/Safari/Chrome - the string might exist in all of them but due to rendering engine differences only show up in Firefox - then it's CSS/HTML issue
2) I don't see it in Firefox 6 (even in the source). I suspect it might be a SESSION thing. For example $node->field_length[0]['view'] is empty if you are missing something in your browser session. So for example you have active session with Firefox but because you haven't logged in with the other browsers - it doesn't show up.
Those are just guesses, without seeing more server side code.
If you view source in each browser you should find that the source looks exactly the same in every browser.
Here are the validation errors on your page.
http://validator.w3.org/check?uri=http%3A%2F%2Fmsvehicles.com%2Fgsa%2Fmobile-mammography-clinic-msv-m-4000-102-40-b&charset=%28detect+automatically%29&doctype=Inline&group=0
Fix all of these and your problem will probably fix itself.

PHP include menu system - Reload not working

I have very simple page at the moment. The only thing that I using PHP for is a switch menu system. So in the switch system i check the variable "menu" to see what it's set to.
So for example if i load the contact info it would be
www.mydomain.com/?menu=contact
in the php switch code under "menu" there is only one thing.
include("contact.php");
Ok, I know this is very simple, but the problem that I am having is when i change the "contact.php" the changes won't be noticeable in the browser, not until i actually go directly to that file. So I would have to browse to www.mydomain.com/contact.php and then i see the difference. After doing that I can go back to "www.mydomain.com/menu?contact" and see the difference.
I have tried to reload, refresh and reload cache command in Firefox, Safari and Chrome. They all work the same way. How can I fix this, it's rather time consuming to refresh two pages each time I need to see the changes.
Are you using a caching system like eaccelerator or APC on your system (phpinfo(); would tell you).
What happens if you print the time() and filemtime() of the template before requiring it, it should tell you when it was last modified.

How to tell clicking "back" to load the cache?

I realize that you can't 100% know that this will work in all browsers. All I care about is IE 8, Chrome, and Firefox. I need some base headers that I can put at the top of my PHP pages to allow the Forward/Back buttons to load the cache.
Update: on every page I have a logged in user box at the top of the page which gives the user access to their account.
I'm looking for a performance increase in the web site. The user having to reload the site when clicking back/forward creates unnecessary the server load.
Edit: After extensive research into caching and my level of knowledge I do not know a good solution. It also appears that most others don't know either.
What you want is jumping back in the page cache. There are various variables that determine if a page is put into the page cache.
Surfin' Safari has recently written a blog about the page cache. In short a page isn't put into it if:
The page is not completely loaded or uninteresting. (404 errors…)
The page is complicated to halt. This is the case if it has Flash elements or movies.
The page has frames.
The page is secure.
The page has an unload event. In their second blog post they write about alternatives.
Those are the rules Webkit follows, I don't know if it's documented for the other browsers. You can never be sure that a page is put into the page cache. It's best to design websites that don't relay on behavior that can change without notice.
Are you using sessions? If so, before calling session_start() call session_ cache_ limiter('') .
When you call session_start() the cache limiter is reset to the value set in session.cache_limiter (which by default is 'nocache'). If you want your pages to cache you need to explicitly set the cache limiter to something else first.
You can experiment with other values (see http://www.php.net/manual/en/function.session-cache-limiter.php) but I find session_ cache_ limiter('') gives the best result when trying to, for example, prevent forms from being reset when sending a user back after an error.
Although keep in mind this may open privacy concerns if your pages hold personal data, as personalized pages will become cached.

Categories