Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Your Ideas Pls Help urgent!! 1

Status
Not open for further replies.

Forri

Programmer
Joined
Oct 29, 2003
Messages
479
Location
MT
Hi

So i have a website which is made up of several php pages (html and php intercombined). Now at the begining of the site the user has to choose a country and set it!

I would like to hold this value SOMEWHERE as it will be used on each different page!

What is the best method to do this and how to do it if possible!! Any ideas..kinda urgent! :>

Thanks
 
There are 3 ways you can do this:

1) Use session variables ($_SESSION[]) to store the country while the user is at the site. Pro: not much extra coding is needed for this. Con: If the user times out, so does his country. Also, the next time the user comes back, he'll have to choose the country again.

2) Store it in a database along with his/her login, if you have the user log in.

3) Save it as a cookie. This means that the variable will be saved on the users computer and next time he/she returns, it will already be set, and you won't have to have them set it anymore, unless they don't have cookies eneabled, or they delete cookies.

Take Care,
Mike
 
I'm trying all these but they are not keeping the values! ie both the $_SESSION and the $_COOKIES!! I don't know why they are loosing the values or not being set at all!

Can i do something to check it out?

ps. i wrote a very simple script have one page that sets the cookies and the other that reads them! This works but my page doesn't!! Am i mssing something or?

Thanks
Nick
 
When using $_SESSION, make sure that you have
Code:
<?php
    session_start();
?>
at the top of every page. Also, set sessions like this:
Code:
    $_SESSION['country'] = 'USA';

The old method of using session_register('country') is outdated and no longer necessary.

Take Care,
Mike
 
Thanks Mike but i went witht he conventional way ...storing them in a table!!

By any chance do you know how to expire a page! Mainly if the user pushes the back button he will be warned of the expired page!?

Thanks
ncik
 
Try this at the top of your page:
Code:
header (&quot;Expires: Mon, 1 Jan 1900 00:00:00 GMT&quot;);

:) Haven't tried it myself yet... **crossing fingers**

Take Care,
Mike
 
Content-type: text/html
Cache-control: no-cache
Pragma: no-cache
Expires: Thu, 01-Jan-2033 01:01:01 GMT

should expire it.
Saw this trick also on web. Let me know if it works.

Add this code to the header of your page:

< script >
history.forward();
< /script >
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top