need help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jaska94
Forum Newbie
Posts: 3
Joined: Thu Dec 17, 2009 3:39 pm

need help

Post by jaska94 »

Hi! I have just a little problem. I want to make a website where user can chose hes own style.
everything is working exept in the very first loading of the page there isnt any style, but why?
the error is Undefined index: css in C:\wamp\www\index.php on line 6. i can understand that theres no value but why?
also when i click the christmas style link i have to press reload to get it :|
stylechooser.php file looks like this:
<?php
$switch = (isset($_GET['mode'])) ? $_GET['mode'] : "index";

switch($switch) {
#option 1
case "christmas":
$css = "/christmas.css";
#setting session.
$_SESSION['css'] = $css;
break;

#option 2
case "fancy":
$css = "/fancy.css";
$_SESSION['css'] = $css;
break;

#reset to the default
default:
$css = "/default.css";
$_SESSION['css'] = $css;
break;
}
?>
And the index.php-s beginning looks like this :
<html>
<head>
<?php
session_start();
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$_SESSION['css']}\" media=\"screen\">";
?>
</head>

<title></title>
<body>
<?php include("style_chooser.php");?>
<?php include("visits.php");?>

<a href='?mode=christmas'>here</a>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: need help

Post by requinix »

You have to call session_start before you can use $_SESSION.
jaska94 wrote:also when i click the christmas style link i have to press reload to get it :|
Could be caching. Or it could be a flaw in how your style switching code works.
jaska94
Forum Newbie
Posts: 3
Joined: Thu Dec 17, 2009 3:39 pm

Re: need help

Post by jaska94 »

added session start to the stylechooser file. Now it says :
A session had already been started - ignoring session_start() in C:\wamp\www\style_chooser.php on line 2

im pretty sure theres no session start nowhere else :D
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: need help

Post by requinix »

Oh, I didn't see the include(). In my defense it's painful to read text like that without nice coloring and formatting.

Code: Select all

<html>
<head>
<?php
session_start();
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$_SESSION['css']}\" media=\"screen\">";
?>
</head>
 
<title></title>
<body>
<?php include("style_chooser.php");?>
<?php include("visits.php");?>
 
<a href='?mode=christmas'>here</a>
You can't echo the $_SESSION["css"] until you determine what it is. And you don't do that until you include style_chooser.php.
Try moving some things around.
jaska94
Forum Newbie
Posts: 3
Joined: Thu Dec 17, 2009 3:39 pm

Re: need help

Post by jaska94 »

thanx tasairis! i included the php file in wrong place , everything works now :D
Post Reply