Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-09-2008, 08:16 PM cookie theme changer
Extreme Talker

Posts: 189
Trades: 0
can someone please tell me whats wrong with my code

PHP Code:
<?php
$day 
60 60 24 60 time(); 
$theme $_POST['theme'];
$dtheme "naruto";


if(isset(
$_COOKIE['theme'])
{
echo 
"<?php include 'theme/ ";
echo 
"$_COOKIE['theme'];";
echo 
".txt";
}
else
{
setcookie('theme'$dtheme$day);
}



?>
simster is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-09-2008, 09:08 PM Re: cookie theme changer
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You don't need to "echo" the php code to include a file. Also, do you want to set the cookie to the new theme if its passed?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-09-2008, 09:13 PM Re: cookie theme changer
Extreme Talker

Posts: 189
Trades: 0
if the cookie doesnt exist i want it to set the cookie to the default theme (naruto)

but if it does it should read it in from the cookie

and if someone changes the them it should change the cookie
simster is offline
Reply With Quote
View Public Profile
 
Old 03-09-2008, 09:16 PM Re: cookie theme changer
Extreme Talker

Posts: 189
Trades: 0
doesnt work and the code is now

Quote:
<?php
$day = 60 * 60 * 24 * 60 + time();
$theme = $_POST['theme'];
$dtheme = "naruto";


if(isset($_COOKIE['theme'])
{
include("theme/$theme.php");
}
else
{
setcookie('theme', $dtheme, $day);
include ("theme/naruto.txt");
}



?>
simster is offline
Reply With Quote
View Public Profile
 
Old 03-09-2008, 09:23 PM Re: cookie theme changer
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP Code:
<?php
 
  $theme 
'naruto';
  
  if (isset(
$_COOKIE['theme']) AND file_exists('theme/' $_COOKIE['theme'] . '.txt'))
  {
    include(
'theme/' $_COOKIE['theme'] . '.txt');
    
$theme $_COOKIE['theme'];
  }
  else
  {
    if (isset(
$_POST['theme']) AND file_exists('theme/' $_POST['theme'] . '.txt'))
    {
      include(
'theme/' $_POST['theme'] . '.txt');
      
$theme $_POST['theme'];
    }
    else
    {
      include(
'theme/' $theme '.txt');
    }
    
    
setcookie('theme'$themetime()+60*60*24*60);
  }
 
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-09-2008, 09:26 PM Re: cookie theme changer
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I just realized that when you include() your theme file, you will not be able to set your new cookie because output will already be sent to the browser.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-09-2008, 09:28 PM Re: cookie theme changer
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You can do this instead (set cookie before including the file)

PHP Code:
<?php
 
  $theme 
'naruto';
 
  if (isset(
$_COOKIE['theme']) AND file_exists('theme/' $_COOKIE['theme'] . '.txt'))
  {
    
$theme $_COOKIE['theme'];
  }
  else
  {
    if (isset(
$_POST['theme']) AND file_exists('theme/' $_POST['theme'] . '.txt'))
    {
      
$theme $_POST['theme'];
    }
 
    
setcookie('theme'$themetime()+60*60*24*60);
  }
 
  include(
'theme/' $theme '.txt');
 
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-10-2008, 04:01 AM Re: cookie theme changer
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Good posting Mgraphic
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 03-10-2008, 05:55 PM Re: cookie theme changer
Extreme Talker

Posts: 189
Trades: 0
i cant change the them with my form

Quote:
<div align="center">

<form method="post" action="index.php">
<select multiple name="theme" size="4">
<option value="Naruto" selected>Naruto</option>
<option value="negima" >Negima</option>
</select>
<input type="submit" value="Change">
</form>


</div>
and my index.php code is
Quote:
<?php

$theme
= 'negima';

if (isset(
$_COOKIE['theme']) AND file_exists('theme/' . $_COOKIE['theme'] . '.txt'))
{
include(
'theme/' . $_COOKIE['theme'] . '.txt');
$theme = $_COOKIE['theme'];
}
else
{
if (isset(
$_POST['theme']) AND file_exists('theme/' . $_POST['theme'] . '.txt'))
{
include(
'theme/' . $_POST['theme'] . '.txt');
$theme = $_POST['theme'];
}
else
{
include(
'theme/' . $theme . '.txt');
}

setcookie('theme', $theme, time()+60*60*24*60);
}

?>

Last edited by simster; 03-10-2008 at 06:00 PM..
simster is offline
Reply With Quote
View Public Profile
 
Old 03-10-2008, 06:11 PM Re: cookie theme changer
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Firstly i think you want to remove the multiple, because you cant have more than one theme at the same time!

and i dont think you need Size
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 03-10-2008, 08:07 PM Re: cookie theme changer
Extreme Talker

Posts: 189
Trades: 0
ill try that now

Last edited by simster; 03-10-2008 at 08:10 PM..
simster is offline
Reply With Quote
View Public Profile
 
Old 03-10-2008, 08:14 PM Re: cookie theme changer
Extreme Talker

Posts: 189
Trades: 0
still doesnt do anything

code:
Quote:
<div align="center">

<form method="post" action="index.php">
<select name="theme">
<option value="Naruto" selected>Naruto</option>
<option value="negima" >Negima</option>
</select>
<input type="submit" value="Change">
</form>

</div>
simster is offline
Reply With Quote
View Public Profile
 
Old 03-10-2008, 11:04 PM Re: cookie theme changer
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Alright, I made a mistake. This will allow you to set a new theme and the comments show what is going on...

PHP Code:
<?php
  
  
// Set default
  
$theme 'naruto';
  
  if (isset(
$_POST['theme']) AND file_exists('theme/' $_POST['theme'] . '.txt'))
  {
    
// Set to new selected theme from previous form
    
$theme $_COOKIE['theme'];
  }
  else if (isset(
$_COOKIE['theme']) AND file_exists('theme/' $_COOKIE['theme'] . '.txt'))
  {
    
// Set to current cookie selected
    
$theme $_POST['theme'];
  }
  
  
setcookie('theme'$themetime()+60*60*24*60);
  include(
'theme/' $theme '.txt');
  
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-11-2008, 06:40 AM Re: cookie theme changer
Extreme Talker

Posts: 189
Trades: 0
im sorry it doesnt work at the moment (with the form changing it)
simster is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to cookie theme changer
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50978 seconds with 12 queries