Use cookies? Sessions? database? I dont know!

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

j0ker21m
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Jul 28, 2003 7:54 am

Use cookies? Sessions? database? I dont know!

Postby j0ker21m » Tue Aug 26, 2003 1:36 pm

I dont know if i can explain this clearly, but I'll try. I have a website using phpclassifieds (if your familiar with it). I have a small weather source I put on there (from weather underground). I have it set in the code to use a variable called $city rather than the actual city name.


Code: Select all

 <a href="http://www.wunderground.com/US/IA/<? echo $city ?>.html">
<img src="http://banners.wunderground.com/banner/gizmotimetempbig_both/language/www/US/IA/<? echo $city ?>.gif"
alt="Click for <? echo $city ?>, Iowa Forecast" height=40 width=467 border="0"></a><br><br><br>
<table width="60%" border="0" cellspacing="0" cellpadding="0">




What I would like to do is have a window popup to where the user can select their city (as this is a locally used website) from a dropdown list and have it set as a cookie, and allow the user to change this value as needed. Then I would like the above script to recall the cookie variable. All attempts I have made haven't worked.
Another Idea would be to recall the city from their account information as they are required to select a city when they register. Only problem with this is it is a classifieds site and most visitors don't register.

Any suggestions on how I would go about this?

Thanks in advance,

j0ker21m

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Tue Aug 26, 2003 1:40 pm

Using an ordinary cookie will work if you want the option to be available to all users, including ones who aren't signed on. Use setcookie() and getcookie() to store and retrieve the setting. If you want it only to work for users who are signed in, then you can just get the city information from their account information in the database.

j0ker21m
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Jul 28, 2003 7:54 am

Thanks

Postby j0ker21m » Tue Aug 26, 2003 1:53 pm

Thats how I've been trying to go about it...but I am just having coding probs I guess. One more quick question for you. What's the syntax for saying:
If variable 1 exists and if variable1 doesnt = variable2 then continue with code? This is what I have and it doesnt seem to work. I guess I dont know how to write the AND part...

Code: Select all

if ($variable1) || ($variable1 != $variable2) {
//continue with code
}

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Tue Aug 26, 2003 1:55 pm

AND is &&
OR is ||

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

cookie implementation

Postby ruturajv » Tue Aug 26, 2003 10:35 pm

One common problem may be you are trying to get the cookie before it is set,

Once the cookie is set, take the user again to the page where information is to be displayed

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Tue Aug 26, 2003 11:18 pm

after getting the new values from user you have to set cookie again to to show data on that values :!: :idea: :arrow:

User avatar
tryton
New php-forum User
New php-forum User
Posts: 49
Joined: Wed Jul 09, 2003 8:25 am
Location: Joze
Contact:

Postby tryton » Wed Aug 27, 2003 6:54 am

Checked your website joker and it looks like its working today.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 6 guests