Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

cookie

Asked Modified Viewed 2,172 times
N
nonaimer
N
nonaimer 10
  • Member, joined since
  • Contributed 68 posts on the community forums.
  • Started 20 threads in the forums
  • Started this discussions
asked
Member

Hello,
How can I make a mod like this:
When a cookie is on your computer,you are redirected to news.php?readmore=$id , if you dont have the cookie,you are redirected to news.php?vote...

something in php language:

<a href='news.php?
if have cookie {
readmore=".$data2['news_id]
} else {
vote
}

thank you
Edited by nonaimer on 29-01-2007 22:51,
0 replies

12 posts

F
fetloser
F
  • Senior Member, joined since
  • Contributed 275 posts on the community forums.
  • Started 2 threads in the forums
answered
Senior Member

if ($_COOKIE["cookie-name"] == "your value") {
//do something
} else {
//do something else
}
0 replies
N
nonaimer
N
nonaimer 10
  • Member, joined since
  • Contributed 68 posts on the community forums.
  • Started 20 threads in the forums
  • Started this discussions
answered
Member

and one more question... how to create a cookie for 24 hours?
0 replies
N
nonaimer
N
nonaimer 10
  • Member, joined since
  • Contributed 68 posts on the community forums.
  • Started 20 threads in the forums
  • Started this discussions
answered
Member

so,how can I create a cookie,when a button is pressed,and after 24hours cookie will be automatically removed?
0 replies
F
fetloser
F
  • Senior Member, joined since
  • Contributed 275 posts on the community forums.
  • Started 2 threads in the forums
answered
Senior Member

setcookie is used for that.

setcookie("TestCookie", $va...e()+3600);

3600 is seconds, so you need to multiply with 24 and use that number.

0 replies
N
nonaimer
N
nonaimer 10
  • Member, joined since
  • Contributed 68 posts on the community forums.
  • Started 20 threads in the forums
  • Started this discussions
answered
Member

how can I make it work?
When I do this:
<a href='setcookie("TestCookie", $value, time()+3600);'>

ir doesnt work... any help?
0 replies
F
fetloser
F
  • Senior Member, joined since
  • Contributed 275 posts on the community forums.
  • Started 2 threads in the forums
answered
Senior Member

make the link
<a href='".FUSION_SELF."?setcookie'>LINK TEXT</a>

and you have to replace the vaule with something or assign $value som sort of something ($value="anything here";) is how you assign it a value.

Then put this somewhere at the top of the page, this will then set the value only if link is clicked.

if (isset($setcookie)) setcookie("TestCookie", $value, time()+3600);
0 replies
N
nonaimer
N
nonaimer 10
  • Member, joined since
  • Contributed 68 posts on the community forums.
  • Started 20 threads in the forums
  • Started this discussions
answered
Member

still nothing i write this:

if (isset($setcookie)) setcookie("VOTING", $value, time()+3600);
$value="Voting_complete";

  require_once "maincore.php";
  require_once "subheader.php";
  require_once "side_left.php";

opentable ('Voting');
echo "<a href='".FUSION_SELF."?setcookie'>SET COOKIE</a>";
if ($_COOKIE["VOTING"] == "Voting_complete") {
echo "smile";
} else {
echo "ot";
}


and nothing... what am I doing wrong?
0 replies
F
fetloser
F
  • Senior Member, joined since
  • Contributed 275 posts on the community forums.
  • Started 2 threads in the forums
answered
Senior Member

not bad, you are getting closer!
This is an example using your data just in a little different order.

Of course you wont see "smiley" until page is rereshed after link is clicked (cookies work like that but can be solved with a redirect - holler if you want code for that)

<?php
/*---------------------------------------------------+
| PHPFusion 6 Content Management System
+----------------------------------------------------+
| Copyright © 2002 - 2006 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------*/
require_once "maincore.php";
  require_once "subheader.php";
  require_once "side_left.php";

$value="Voting_complete";
if (isset($setcookie)) setcookie("VOTING", $value, time()+3600);


 

opentable ('Voting');
echo "<a href='".FUSION_SELF."?setcookie'>SET COOKIE</a>";
if ($_COOKIE["VOTING"] == "Voting_complete") {
echo "smile";
} else {
echo "ot";
}

require_once "side_right.php";
require_once "footer.php";
?>
0 replies
N
nonaimer
N
nonaimer 10
  • Member, joined since
  • Contributed 68 posts on the community forums.
  • Started 20 threads in the forums
  • Started this discussions
answered
Member

thanks a lot!
Everything works fine! ;)
0 replies
J
Josso
J
Josso 10
–––
Without faith, nothing is possible. With it, nothing is impossible
  • Senior Member, joined since
  • Contributed 309 posts on the community forums.
  • Started 1 thread in the forums
answered
Senior Member

I have followed the thread and I have a question:
How can I make a link there delete the cookie??
0 replies
N
nonaimer
N
nonaimer 10
  • Member, joined since
  • Contributed 68 posts on the community forums.
  • Started 20 threads in the forums
  • Started this discussions
answered
Member

dunno... ask fetloser
0 replies
F
fetloser
F
  • Senior Member, joined since
  • Contributed 275 posts on the community forums.
  • Started 2 threads in the forums
answered
Senior Member

Hi!

Not so hard to delete a cookie. They stay in your browsers cookie area until the time you set for them expired. So all you need to do is set it with same name but a timestamp back in time.

<?php
/*---------------------------------------------------+
| PHPFusion 6 Content Management System
+----------------------------------------------------+
| Copyright © 2002 - 2006 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------*/
require_once "maincore.php";
  require_once "subheader.php";
  require_once "side_left.php";

$value="Voting_complete";
if (isset($setcookie)) setcookie("VOTING", $value, time()+3600);

if (isset($deletecookie)) setcookie("VOTING", $value, time()-3600);
 

opentable ('Voting');
echo "<a href='".FUSION_SELF."?setcookie'>SET COOKIE</a>";
echo "<br><a href='".FUSION_SELF."?deletecookie'>Delete COOKIE</a>";
if ($_COOKIE["VOTING"] == "Voting_complete") {
echo "smile";
} else {
echo "ot";
}

require_once "side_right.php";
require_once "footer.php";
?>


only diff here is the time of deletecookie is in the past and another isset to ensure this only applies if delete cookie is clicked.
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 12 posts
  • Votes 0 votes
  • Topic users 3 members

0 participants

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet