change title with php

  • xlgfx
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 03, 2006
  • Posts: 222
  • Status: Offline

Post October 13th, 2006, 11:21 am

ok, i have a title bar on my website, and i want the text in the bar to change with each page. im currently using a script that dont work :cry: but i know i cant be too far off. im getting this error:

Code: [ Download ] [ Select ]
Parse error: syntax error, unexpected $end in /home/vipbarga/public_html/*plum*/content/articles.php on line 6


heres the code that im using to change the page. on index.php im using this line:

Code: [ Download ] [ Select ]
<?php print $title; ?>


and then on my pages that i want titles for i included this:

Code: [ Download ] [ Select ]
<?php
function header($title){
if($title){
$title="Articles";
}
?>
  1. <?php
  2. function header($title){
  3. if($title){
  4. $title="Articles";
  5. }
  6. ?>


i know somebody here can resolve my problem so dont be shy :D
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 13th, 2006, 11:21 am

  • Prime
  • Professor
  • Professor
  • User avatar
  • Joined: Dec 05, 2005
  • Posts: 935
  • Loc: Liverpool
  • Status: Offline

Post October 13th, 2006, 11:57 am

Hi,

What are the contents of articles.php :?:

Cheers, Prime ... :D
my seo experience
  • xlgfx
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 03, 2006
  • Posts: 222
  • Status: Offline

Post October 13th, 2006, 12:20 pm

that code is the only content there. its in the php. theres nothing else on the page.

Post October 13th, 2006, 1:15 pm

You need an extra ending curly bracket to end the function called "header()". I also suggest using "echo" instead of "print" as it is just a little faster/better than print for less complex things.

http://www.faqts.com/knowledge_base/vie ... d/1/fid/40
Why no, no I'm not.
  • xlgfx
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 03, 2006
  • Posts: 222
  • Status: Offline

Post October 13th, 2006, 1:41 pm

ok ive changed the code and included that other bracket but now im getting an error stating this:

Code: [ Download ] [ Select ]
Parse error: syntax error, unexpected '}' in /home/vipbarga/public_html/*plum*/content/articles.php on line 3


heres what i did.

Code: [ Download ] [ Select ]
<?php
function header($title){
if($title) } {
$title="Articles";
}
?>
  1. <?php
  2. function header($title){
  3. if($title) } {
  4. $title="Articles";
  5. }
  6. ?>
  • Nightslyr
  • Proficient
  • Proficient
  • No Avatar
  • Joined: Sep 21, 2005
  • Posts: 254
  • Status: Offline

Post October 13th, 2006, 2:12 pm

xlgfx wrote:
heres what i did.

Code: [ Download ] [ Select ]
<?php
function header($title){
if($title) } {
$title="Articles";
}
?>
  1. <?php
  2. function header($title){
  3. if($title) } {
  4. $title="Articles";
  5. }
  6. ?>


What you need to do is this:

Code: [ Download ] [ Select ]
<?php
function header($title){
  if($title){
   $title = "Articles";
  }
}
?>
  1. <?php
  2. function header($title){
  3.   if($title){
  4.    $title = "Articles";
  5.   }
  6. }
  7. ?>


With the way you had it above, you were ending your header function right at the if-conditional.
  • xlgfx
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 03, 2006
  • Posts: 222
  • Status: Offline

Post October 13th, 2006, 2:16 pm

well that got me away from the parse error. now i got this.

Code: [ Download ] [ Select ]
Fatal error: Cannot redeclare header() in /home/vipbarga/public_html/*plum*/content/articles.php on line 2
  • xlgfx
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 03, 2006
  • Posts: 222
  • Status: Offline

Post October 13th, 2006, 2:25 pm

maybe im going about this all wrong. i have a title bar above my main content that i want the text to change on. not the window bar, if that might be the problem. I have no idea how to go about doing this. i have a little php knowledge but not enough to write my own scripts no matter how basic this is.

Post October 13th, 2006, 3:20 pm

LMFAO, dur I can't believe I haven't seen this before. The function header() is already in PHP, meaning you cannot make it... Give your function a different name.
Why no, no I'm not.
  • xlgfx
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 03, 2006
  • Posts: 222
  • Status: Offline

Post October 13th, 2006, 3:39 pm

ok, im totally confused at this point. wouldnt i have to define the function?

this seems like alot of stress just over a title bar..

i hate php :-(

Post October 13th, 2006, 3:49 pm

Okay in PHP just like many other languages, there are already functions that do things. header() is a predefined function used to send raw HTTP headers (click Header() for more information). All you have to do is make your function something like myheader(), just rename it...
Why no, no I'm not.
  • xlgfx
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 03, 2006
  • Posts: 222
  • Status: Offline

Post October 13th, 2006, 8:55 pm

PunkPuke wrote:
Okay in PHP just like many other languages, there are already functions that do things. header() is a predefined function used to send raw HTTP headers (click Header() for more information). All you have to do is make your function something like myheader(), just rename it...


i did that. now i got this and it still doesnt work. this is the code on articles.php

Code: [ Download ] [ Select ]
<?php
function myheader($title){
  if($title){
   $title="Articles";
  }
}
?>
  1. <?php
  2. function myheader($title){
  3.   if($title){
  4.    $title="Articles";
  5.   }
  6. }
  7. ?>


and on index.php:

Code: [ Download ] [ Select ]
<?php print $title; ?>
  • knexor2
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 27, 2006
  • Posts: 445
  • Loc: US
  • Status: Offline

Post October 13th, 2006, 9:14 pm

What errors are you currently getting? (Paste the output?)
"People can school you, but you must educate yourself." ~ John Taylor Gatto
Tech Knack Blog
The purpose of these forums is not to get an answer, but to learn an answer.
  • xlgfx
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Sep 03, 2006
  • Posts: 222
  • Status: Offline

Post October 13th, 2006, 9:17 pm

im not getting any errors at all. but its not showing the text on my title bar
  • knexor2
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 27, 2006
  • Posts: 445
  • Loc: US
  • Status: Offline

Post October 13th, 2006, 9:22 pm

Ok.

xlgfx wrote:
...this is the code on articles.php

Code: [ Download ] [ Select ]
<?php
function myheader($title){
  if($title){
   $title="Articles";
  }
}
?>
  1. <?php
  2. function myheader($title){
  3.   if($title){
  4.    $title="Articles";
  5.   }
  6. }
  7. ?>


and on index.php:

Code: [ Download ] [ Select ]
<?php print $title; ?>


These two pieces of code don't seem to be related at all. But anyway...

On articles.php, you have the if statement inside a function -- if the function is not called, $title will remain undefined.
Also, the if statement is saying "if $title is not false (or it is defined), set it equal to 'Articles' ".

On index.php, you haven't defined $title before you print it, so it will print nothing (defaulting to $title="";)
"People can school you, but you must educate yourself." ~ John Taylor Gatto
Tech Knack Blog
The purpose of these forums is not to get an answer, but to learn an answer.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 13th, 2006, 9:22 pm

Post Information

  • Total Posts in this topic: 37 posts
  • Users browsing this forum: No registered users and 120 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.