Jump to content
MakeWebGames

header help


skizzy

Recommended Posts

what im trying to do is set different headers for different classes that i got setup on the register page and have class in the users table

but i get [11-Oct-2011 05:20:31] PHP Parse error: syntax error, unexpected $end in C:\xampp\htdocs\header.php on line 45

here is my code

<?php
$class=$ir['class'];
class headers {

function startheaders() {



global $ir, $set;

echo <<<EOF

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>{$set['game_name']}</title>}

function userdata($ir,$lv,$fm,$cm,$dosessh=1)

{

global $db,$c,$userid, $set;

}


if '.$class.'="pirates"

{
include "header2.php";
}
if '.$class.'="nobles"

{
include "header7.php";
}
}
}
}
?>
Edited by skizzy
Link to comment
Share on other sites

<?php
$class=$ir['class'];
class headers {

function startheaders() {



global $ir, $set;

echo <<<EOF

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>{$set['game_name']}</title>}

function userdata($ir,$lv,$fm,$cm,$dosessh=1)

{

global $db,$c,$userid, $set;

}


if '.$class.'="pirates"

{
include "header2.php";
}
if '.$class.'="nobles"

{
include "header7.php";
}
}
}
}
?>
Link to comment
Share on other sites

Try this:

<?php

class headers {
   function startheaders() {
       global $set;
       echo '
       <!DOCTYPE html>
       <html lang="en">
       <head>
       <meta charset="utf-8">
       <title>'.htmlentities($set['game_name'], ENT_QUOTES, 'UTF-8').'</title>
       ';
   }

   function userdata ($ir, $lv, $fm, $cm, $dosessh = 1) {
       if ($ir['class'] == 'pirates') {
           include 'header2.php';
       } else if ($ir['class'] == 'nobles') {
           include 'header7.php';
       } else { 
           //Include a default one perhaps?
       }
   }
}
Link to comment
Share on other sites

ok that script works but had to take out

class headers {

function startheaders() {

global $set;

echo '

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>'.htmlentities($set['game_name'], ENT_QUOTES, 'UTF-8').'</title>

';

}

now i get

[11-Oct-2011 06:19:43] PHP Fatal error: Class 'headers' not found in C:\xampp\htdocs\globals.php on line 74

fixed above error now i get

[11-Oct-2011 06:27:34] PHP Fatal error: Call to undefined method headers::menuarea() in C:\xampp\htdocs\globals.php on line 91

and also Djkanna a default isnt necessary because u have to be one or the other as it is set via register

Edited by skizzy
Link to comment
Share on other sites

That's because you took out that part of the code ...

the first line is "class headers" which tells php to create that class. Why have you removed that part of the code? you need it..

The function menuarea() should be a part of the headers.php file, if you don't have it, add it.

 

and also Djkanna a default isn't necessary because you have to be one or the other as it is set via register

then use the following and leave the else if out

 

 
if ( $value ="thing") {
  // action1
} else {
  // action 2
}
Link to comment
Share on other sites

That's because you took out that part of the code ...

the first line is "class headers" which tells php to create that class. Why have you removed that part of the code? you need it..

The function menuarea() should be a part of the headers.php file, if you don't have it, add it.

 

then use the following and leave the else if out

 

 
if ( $value ="thing") {
  // action1
} else {
  // action 2
}

Actually he needs to keep the else if

Link to comment
Share on other sites

Okay then you tell me what the point is of the following

 

if ($ir['class'] == 'pirates') {
           include 'header2.php';
       } else if ($ir['class'] == 'nobles') {
           include 'header7.php';
       } else {
           //when you are doing nothing at all
       }

 

When the script comes to a point where you are not a pirate nor a noble, it won't include any header, and probably breaking everything as I can imagine that the headers have some basic, yet very needed functionality to the page. If the script sets one of the two by default, he can just use an if else and be done with it. You'll also be sure that, no matter what, you'll always include one header. If he uses the current setup, the script will check if the userclass is a pirate, and if not move on to the next check where it will check whether the userclass is a noble. But if it isn't a noble, it will fall back to the else block, which does not exist here. Since these things are set on register, I doubt there will be an issue with the correct working of the code. However, you've added an unneeded check. Also, by not using an else, you don't have any fallback in case something goes wrong. If you only have two options, use an if else, and leave out the else if. If you do use else if's, fine, but at least use an else as well and don't leave it empty...

Link to comment
Share on other sites

DjKanna gave him that part of the script without knowing what else would be added to it, ofcoure there is going to be an header for people that haven't chosen to be a noble or a pirate therefor he needs the elseif in the script before he adds the next part to it

I did that part, like the way I did as I did not know how you came about becoming a noble or a pirate. It was either a choice of picking which, or being promoted therefore I picked the latter and did it the way I did.

Now I know that you have to pick on register, either noble or pirate, a simple if/else will do fine, in that sense Nickson is right.

Link to comment
Share on other sites

DjKanna gave him that part of the script without knowing what else would be added to it, ofcoure there is going to be an header for people that haven't chosen to be a noble or a pirate therefor he needs the elseif in the script before he adds the next part to it

Check what he originally posted, there are only 2 classes, if a 3rd one would appear, I would find it strange. Otherwise, what DjKanna said :)

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...