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
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');
?>

Link to comment
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.