Okay now I'm trying to setup my site to have 2 different layouts. Now currently the site is programmed in php.
What I was thinking about doing was if someone wanted to change the layout they could simply click a link and it would set a cookie or I believe a session(?) as it's called in php. Now from there whenever someone comes to the site inside the index.php there would be an if statement that would look something like this:
<?php
if()
{
include("top.shtml");
include("middle.shtml");
include("bottom.shtml");
}
else
{
include("top2.shtml");
include("middle2.shtml");
include("bottom2.shtml");
}
?>
Now I don't know if this would work, but in theory I think it would. I'm just wondering what code would I need to make a link to create a session, and then from there what statement would I need to have for the if statement to work?
Thanks.
Session & if question
Moderator: General Moderators
To work with sessions:
Index Page:
Then on changestyle.php:
Index Page:
Code: Select all
<?php
session_start();
if($_SESSION['style2']) //if session variable = 2
{
include("top2.shtml");
include("middle2.shtml");
include("bottom2.shtml");
}
else
{
include("top.shtml");
include("middle.shtml");
include("bottom.shtml");
echo "<a href="changestyle.php">Change the style!</a>";
}
?>Code: Select all
<?php
session_start();
$_SESSION['style2'] = "TRUE"; //set session to TRUE
header("Location: index.php"); //redirect back to index.php
?>And where would I put that code? Becuase I replaced it where session_start() was but it is giving me this error now:
Warning: Trying to destroy uninitialized session in /home/break.php on line 2
Warning: Cannot add header information - headers already sent by (output started at /home/break.php:2) in /home/break.php on line 4
Warning: Trying to destroy uninitialized session in /home/break.php on line 2
Warning: Cannot add header information - headers already sent by (output started at /home/break.php:2) in /home/break.php on line 4
Straight from PHP.net:
Use the second one.Example 1. Destroying a session
Example 2. Destroying a session with $_SESSIONCode: Select all
<?php // Initialize the session. // If you are using session_name("something"), don't forget it now! session_start(); // Unset all of the session variables. session_unset(); // Finally, destroy the session. session_destroy(); ?>Code: Select all
<?php // Initialize the session. // If you are using session_name("something"), don't forget it now! session_start(); // Unset all of the session variables. $_SESSION = array(); // Finally, destroy the session. session_destroy(); ?>