Saving session data with Javascript, or similar solution - php

Basically what I'm trying to achieve is a basic back capability. User goes into Girls listing, which shows him a location screen. Selects a location, and the locations are replaced by images of girls from that location using AJAX. User clicks on a particular girl to view her profile. Now the user wants to go back and have a look at a different girl from that profile - he'd have to go through the location selection process yet again.
What I would like to achieve is to save the location screen the user was in using javascript - just simply save the whole contents of the container div, for them to be reinserted into the dom when the back button (the in page back button, not browser) is pressed. Now the way I was thinking of doing it is passing the string onto php, saving the string using php to flashdata, and then when back button is pressed requesting that data.
Anyone got any simpler solution for what I'm trying to achieve? You can go on www.discreetdelights.co.uk to see what im trying to achieve - a word of caution though, loads of adult content on there.

You could save this data in a cookie.
Javascript cookie functions

Related

PHP - Browser BACK button crashes the website

I am a newbie to programming. I have a PHP website which works as follows
Index Page - Search Results - Show a Product
The site user enters search critera on Index Page and the page is POSTed to Search Results page. From there, the site user clicks on a Product href that takes him to the Product Details. This is working fine till here.
The problem occurs when the user click the browser BACK button. The Search Result page comes up totally crashed and the user has to press F5/Browser Refresh to re-submit it. Any idea/technqiue that I can use to avoid this crash?
When a browser goes back to a page that comes from POSTing some data, the browser often times needs to re-POST the data in order to get the same page back. Since that can sometimes be bad (e.g. re-POSTing an order form), many browsers require the user to force a refresh with a warning.
You can generally use a GET instead of a POST form to avoid this.
An idea would be using GET for the method of your search form instead of POST (that apparently you are using). That way, even if going back in browser history, your server could re-supply its search results.
You would need the following:
change method="post" to method="get" in your search form
change every $_POST relating to the search form data to $_GET in your search form processing php file.
Of course, it could not work for your specific usecase. That's just an idea.

AJAX VS PHP for dynamic web pages?

Why use AJAX for dynamic web pages when you can do it only with php?
The main reason to bother with AJAX is User Experience (UX).
Now AJAX won't necessarily improve UX in every single instance so in a lot of places sticking with pure PHP is perfectly okay.
But imagine the case where you have a text field on the site and a link to vote on something. Kinda like this site. When you add AJAX your users won't loose the text they entered in the textfield when they decide to vote on the link! How incredibly useful!
So if you care about your user's experience it is a good idea to use AJAX in situations like that.
PHP creates and outputs the Content to the Client Browser as it's a Server-Side Language and that's what it was built for, so on a request your code will access database, files etc. and then output the constructed html/text to the client.
Ajax just gives the User a more Desktop like feel. For example deleting a record and instead of the entire page reloading just letting the one element disappear from say a list and letting the server know that the record is to be deleted. But Remember to let the User know when you are busy sending data to the server (With a progress bar in .gif format for example). As lot's of user feel that if nothing happens on the screen to notify them, that the application is frozen which means they will either reload the page or just try to click the button again.
But you will need to provide some sort of compatibility with browsers that have Javascript disable and thus cannot use your AJAX functions, just something to keep in mind.
AJAX stands for Asynchronus Javascript and XML, meaning that a page can get new data, without having to reload a page.
PHP cannot send data without reloading the whole page. A user has to press a button, to send data.
An example of AJAX is for example google suggestions or the tag suggestions on this website.

Make all hyperlinks on a PHP page, post a form end then redirect

The short version of what I am looking to do is make a "safe" and idiot-proof page, at least as much as possible.
I have researching the best way to make every hyperlink on a page (ie. standard menus used on the page or any other hyperlinks outside of a HTML form) submit/POST the form information and then redirect to the page clicked on.
For some reason not all users remember the "Save" button before clicking on something else. Then they are upset because they didn't save their information. I would much rather have all the information be saved before sending them on to the hyperlink's URL.
Helpful information:
- This is on a PHP based project.
- I have already put in place code to "detect" what kind of page is in use and if the feature is needed.
- I have header() redirects in some places for other items, so that is nothing new.
- I have looked at javascripts to add, when needed, so that the form is POSTed, and found some options for that.
At this point I can't get the final steps put together, such as a javascript that would POST the information AND store the URL that the hyperlink was supposed to go to. Process the POST information and then redirect to the stored URL.
Dream Example:
onclick="submitformandforward("Example_form", "http://example.mysite.com/example_page.php?querystring=Y")"
Any suggestions, tips, examples, etc are warmly welcomed!
Thanks.
KH
Javascript is the tool you require...
remember some people may have it switched off...
Wehn some clicks a link - check that the form values have been altered - if not carry on - if they have inform that that changes need saving...

How do I create a .php for my Google map that saves basic user content?

I have a basic map and it is set up to take user (no need to sign up, just click and add details, then submit) input, it is just a plain text field. I know I need to set-up a php to store the new data as people enter it but I am a little lost. I searched but did not see an Q&A already, if it exists a redirect would be great. Thanks in advance!
Here is the page if you'de like to see the source, very basic. http://www.nextepisodepgh.org/worldartproject.html
Once the user has clicked on the button you need to do a post back of the form (either directly or indirectly via ajax) to your php page. Your php would simple just grabbed the get or post variable and save it to the database.

Simple question about javascript history.go

I have a classifieds website.
In every classified, there is a back link which simply takes the browser back one step.
This is because when users search classifieds, and click on one to view it, they can easily go back with a link also (instead of only the browser back button).
Here is the problem, if the classified is entered directly into the adress bar of a browser, or if somebody bookmarked a classified, then this back-link would take them someplace else...
Is there any way of making sure that the previous page is a certain page (index.php in my case)?
This way I would only display the back link if the previous page was index.php...
Thanks
You can't query history data. A slightly better option is to read the Referrer server variable and create your "Back" link to it. It's not very much stronger than history.go(), though. Try using a common index page instead.
Why not just insert a link to index.php directly? That way you have complete control over the target of the link. No need for JavaScript.
You should track their session within PHP or whatever language you're using in order to have an effective "back" button.
You could pull the data with document.referrer but that will not always give you the previous page. Sadly I am not sure of a way to achieve a "Back" button via javascript without using some kind of scripting language to track a user either via cookie or session.

Categories