Jump to content


Photo

cookies for choosing site structure


  • Please log in to reply
3 replies to this topic

#1 story97

story97
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 18 October 2006 - 10:07 AM

Hello,

I'm a designer, not a coder, but I'm in need of a little help.

The site i'm working on now has a flash header and menu. This can be a problem for people with Active-X turned off. So I want to offer an option.

Load the site using the flash. Right under the menu, have a link "Non flash site". Now, by itself this might be simple. but again, i'm not a programmer. I'd like this setting stored in a persistent cookie so the user only has to see things they don't want to once.

Is this too broad of a question?

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 18 October 2006 - 02:16 PM

No, it's not broad question...

On your page, check if the cookie is present, if it is set, then show output based on the cookie value. If it's not set, add your link Non flash site that point back to that page and set the cookie, and then show the page where non flash content is shown!

example... (change .domain.com) to (.your_domain.com)

<?php

// page

// show flash, default

$type = 1;

/* first check if we have display change request */

if ( isset ( $_GET['display'] ) )
{
	$test = intval ( $_GET['display'] );

	if ( $test == 0 || $test == 1 )
	{
		// valid change request

		$type = $test;
	}

	setcookie ( 'non_flash', $type, ( time () + 60*60*24*365 ), '/', '.domain.com' );
}

/* else if cookie is set */

else if ( isset ( $_COOKIE['non_flash'] ) )
{
	$test = intval ( $_COOKIE['non_flash'] );

	if ( $test == 0 || $test == 1 )
	{
		// valid cookie value

		$type = $test;
	}
	else
	{
		// cookie set, but not a valid cookie value, so reset the default

		setcookie ( 'non_flash', $type, ( time () + 60*60*24*365 ), '/', '.domain.com' );
	}
}
else
{
	// no cookie set, so set it!

	setcookie ( 'non_flash', $type, ( time () + 60*60*24*365 ), '/', '.domain.com' );
}

// now show your page based on $type

if ( $type == 1 )
{
	// flash content

	echo "<div align='center'>This is a flash filled page<br /><br />Show <a href='/index.php?display=0'>non flash</a> page always!</div>";
}
else
{
	// non flash content
	echo "<div align='center'>This is a page with no flash<br /><br />Show <a href='/index.php?display=1'>flash</a> page always!</div>";
}

?>


me!

#3 story97

story97
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 18 October 2006 - 02:45 PM

Wow fantastic.

I'm remote right now But I'll give this a shot in a  couple hours. I REALLY appreciate it.

#4 story97

story97
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 18 October 2006 - 02:53 PM

Nevermind I copied and pasted the code to my PDA then to the site.

This is exactly what I wanted. Thank you so much!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users