Jump to content

Recommended Posts

Trying to sort out setting a cookie that allows visitor to decide which sub domain to go directly to in subsequent visits.

 

Somewhat complicated by the fact that the sub domains are running seprate instances of wordpress.

 

Here's the code... any suggestions appreciated!

 

<?php
if (isset($_POST['submitted']))
{
$site=$_POST['site'];
setcookie("SitePref",$site, time() + 60*60*24*30, 'historybee.com');
if ($site == 'ms')
{
header("Location: http://ms.historybee.com/"); 
} 
elseif ($site == 'hs') 
{
		define('WP_USE_THEMES', true);
		require('./wp-blog-header.php');
}

} else {

//if we have a cookie, load the site
if (isset($_COOKIE['SitePref'])) 
{
		if (($_COOKIE['SitePref']) == 'hs') {
			define('WP_USE_THEMES', true);
			require('./wp-blog-header.php');
	   		} else { 
			header("Location: http://ms.historybee.com/");
			}

} else { //if we don't have a cookie, load the form ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>The National History Bee</title>
</head>
<body style="margin:0;padding:0;background: url('http://ms.historybee.com/wp-content/themes/makinghistoryblue/img/body_bg_hb5.jpg') repeat-x scroll center top #F2BF3B;">

<div align="center" style="width:800px;margin:0 auto;background:#fff;">

<p><img src="http://ms.historybee.com/wp-content/themes/makinghistoryblue/img/nhb_logo.png">

<p><h1>Welcome to the National History Bee!</h1>

<p>The National History Bee has both High School and Middle School competitions. 

<p>Please choose which site you would like to visit.  Your choice will be remembered for 30 days.

<form action= "<?php echo $_SERVER['PHP_SELF']; ?>" method ="POST">

<input type="radio" name="site" value="ms"> Middle School Competition

<input type="radio" name="site" value="hs"> High School Competition

<input type ="hidden" name="submitted" value="true">

<p><input type="submit" value="Remember My Choice">
</form>
<br /><br /><br />
</div>
</body>
</html>

<?php } } ?>

Link to comment
https://forums.phpfreaks.com/topic/249156-cookie-to-direct-to-sub-domain/
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.