Jump to content

cookie form


cheesycarrion

Recommended Posts

I'm trying to make a form with a checkbox for setting if you want to see the welcome page when you go to my site. I have three pages:

settings form - /directory.php?page=settings - [url=http://carrion.9999mb.com/directory.php?page=settings]http://carrion.9999mb.com/directory.php?page=settings[/url]

[code]<div class="newsarticle">
<div class="newsarticletitle">
Settings
</div>
<div class="newsarticlebody">
<p><b><img src="images/icons/notice.png" />These are saved as cookies on your computer. You must have cookies enabled for these settings to work right. They won't stay attached to your account on CC.</b></p>

<form action="directory.php" method="GET">
<input type="hidden" name="page" value="settings" />
<input type="hidden" name="location" value="2" />

<!-- I put these hidden forms here because the results page isn't right on directory.php; I have lots of other pages in it too. -->
<!-- I didn't know how to say "if the checkbox is checked" in the results page so I used a textbox. Please help me with this too. :) -->

<p><input type="text" name="homeswitch" value="<?php
if ($_COOKIE['homeswitch']=='1')
{
echo '1';
}
elseif ($_COOKIE['homeswitch']=='0')
{
echo '0';
}
else
{
echo '1';
// by default the homepage is on.
}
?>" /> Display Welcome Page - Type 1 or 0</p>
<p><input type="submit" value="done" /><input type="reset" value="cancel" /></p>
</form>
</div></div>[/code]

results form - /directory.php?page=settings&location=2 - [url=http://carrion.9999mb.com/directory.php?page=settings&location=2]http://carrion.9999mb.com/directory.php?page=settings&location=2[/url]

[code]<?php
if ($homeswitch >= "1")
{
setcookie("homeswitch", "1", time()+1000000000);
// this one says that it's enabled and to keep the cookie for one billion seconds, I think.
}
elseif ($homeswitch == "0")
{
setcookie("homeswitch", "0", time()-3500);
// this should be to delete the cookie
}
?>[/code]

results form - /index.php - [url=http://carrion.9999mb.com/]http://carrion.9999mb.com/[/url]

[code]<?php
if ($_COOKIE['homeswitch']=="1")
{
header ("location: directory.php");
}
else
{
// the index page is displayed here.
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/35065-cookie-form/
Share on other sites

You'll want to set it, during your inital login-registration...  and you'll be checking for it from your index, (if you want) or on links after one views intial site for the first time.

session_start;
  session_register("s_email");

----------

http://us3.php.net/manual/en/features.http-auth.php
Link to comment
https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-165516
Share on other sites

here's what it is now:

settings page (with unimportant parts cut out):
[code]<p><input type="checkbox" name="homeswitch" value="homeon" <?php
if ($_COOKIE['homecookie']=='1')
{
echo 'checked';
}
elseif ($_COOKIE['homecookie']=='0')
{
echo '';
}
else
{
echo 'checked';
}
?> /> Display Welcome Page</p>[/code]

I cut a lot of other stuff from the page out because I made a stylesheet switcher script in the same form.

That submits to this page (GET), again cutting out the bit for the style changer:

[code]<?php
$cookieTime = time() + 60*60*24*120;
$homeswitch = $_GET["homeswitch"];
session_start;
  session_register("homepageon");
if ($homeswitch==null)
{
setcookie("homecookie", "0", $cookieTime);
}
elseif ($homeswitch=="homeon")
{
setcookie("homecookie", "1", $cookieTime);
}
?>[/code]

and on the index page

[code]<?php
if ($_COOKIE['homecookie']=="0")
{
header ("location: directory.php");
}
else
{
// the 'click to enter' page is here
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/35065-cookie-form/#findComment-166118
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.