Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.