Jump to content

[SOLVED] else include and cookies dont mix


vote-for-pedro

Recommended Posts

Hi noob on the board here i hope someone can help me.

 

im using cookies on my site they define what style sheet is to be used. only problem is until the user selects a style no cookie is made.

 

im using this code to show a piece of flash.

 

if(isset($_COOKIE['STYLE']))
    {
       include($_COOKIE['STYLE'].'.php');
        exit;
    }
else 
    {
include("0.php")

    {

 

i can use

include($_COOKIE['STYLE'].'.php');

to show the flash if there is a cookie but other wise nothing will show up.

 

include("0.php")

will work on its own but the whole thing together wont work.

 

im pretty sure ive made a simple mistake but i cant see it.

ive also tryed using the

include($_COOKIE['STYLE'].'.php');
break;
default:
require('0.php');

but no good either. Any advice? 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/57276-solved-else-include-and-cookies-dont-mix/
Share on other sites

That's a neater way of putting it. Saves on using the elseif's.

If $_COOKIE['STYLE'] isn't set $style defaults to 0, so including $style should work fine.

<?php
$style = isset($_COOKIE['STYLE']) ? $_COOKIE['STYLE'] : '0';
include($style . '.php');
?>

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.