Re: [PHP] accessing variable value

2008-07-20 Thread Chris
Sudhakar wrote:
 i need help with accessing the value of a variable from a different page.
 
 i have an index.php file which has 2 files included to display header and
 footer and the center portion changes based on the link clicked on the
 footer.
 
 header.php
 
 ?php
 echo h2 Text from header.php file /h2;
 ?
 
 footer.php
 
 ?php
 $title=Title of Footer Page;
 ?
 a href=index.php?page=webWeb Development/a | a
 href=index.php?page=softwareSoftware /a
 
 index.php
 
 ?php
 $pagename=$_GET[page];
 $title=Index page of Company name;
 ?
 html
 head
 title?php echo $title; ? /title
 meta name=keywords content=?php echo $keyword; ?
 meta name=description content=?php echo $pagedescription; ?
 /head
 body
 ?php include(header.php);  ? p /p
 centerThis is the text in the center/center p /p
 ?php
 if($pagename==web)
 {
 include(web.php);
 }
 if($pagename==software)
 {
 include(software.php);
 }
 ?
 ?php include(footer.php);  ?
 /body
 /html
 
 whenever i click the links for Web Development or Software which appears
 from the footer a query string is passed to index.php I am able to display
 the content of web.php and software.php using the if() condition and
 include()
 what i need to display is a different title for web.php and software.php
 when a user clicks Web Development along with the content i want the title
 of the page to change for SEO purpose. i have defined $title differently in
 web.php and software.php however presently the title being displayed for
 index.php when a user clicks web.php and software.php the title is the same
 Index page of Company name as this is defined in index.php and my title
 tag is written as
 title?php echo $title; ? /title however the title tag remains the same
 whether i click web development or software link. how change i change the
 code to display different titles.


?php
$pagename = '';
if (isset($_GET['pagename'])) {
$pagename = strtolower($_GET['pagename']);
}

switch ($pagename) {

// hardcode the pages you *know* exist.
// don't just include $pagename.php
// as i can make up a pagename of whatever i like
// and it will break your site

// i know web.php and software.php exist
// so if the pagename is one of those,
// just include the relevant file.
case 'web':
case 'software':
include($pagename.'.php');
break;

// just in case I remove the pagename variable from the query string
// or make up a random pagename
// make sure you set up some default values!
default:
include('defaults.php');
}
?
html
head
title
?php echo $title; ?
/title
...
body
?php
echo $content;

include 'footer.php';



inside the 'web.php' and 'software.php' files, set your variables:

in web.php:
?php
$title = 'This is the web.php page title';
$keywords = 'These are the keywords for the web.php page';

$content = EOD
This is the content of the page.
Read up about heredoc syntax here:

http://www.php.net/heredoc

EOD;

and to the same inside the software.php and any other files you need.

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] accessing variable value

2008-07-19 Thread Sudhakar
i need help with accessing the value of a variable from a different page.

i have an index.php file which has 2 files included to display header and
footer and the center portion changes based on the link clicked on the
footer.

header.php

?php
echo h2 Text from header.php file /h2;
?

footer.php

?php
$title=Title of Footer Page;
?
a href=index.php?page=webWeb Development/a | a
href=index.php?page=softwareSoftware /a

index.php

?php
$pagename=$_GET[page];
$title=Index page of Company name;
?
html
head
title?php echo $title; ? /title
meta name=keywords content=?php echo $keyword; ?
meta name=description content=?php echo $pagedescription; ?
/head
body
?php include(header.php);  ? p /p
centerThis is the text in the center/center p /p
?php
if($pagename==web)
{
include(web.php);
}
if($pagename==software)
{
include(software.php);
}
?
?php include(footer.php);  ?
/body
/html

whenever i click the links for Web Development or Software which appears
from the footer a query string is passed to index.php I am able to display
the content of web.php and software.php using the if() condition and
include()
what i need to display is a different title for web.php and software.php
when a user clicks Web Development along with the content i want the title
of the page to change for SEO purpose. i have defined $title differently in
web.php and software.php however presently the title being displayed for
index.php when a user clicks web.php and software.php the title is the same
Index page of Company name as this is defined in index.php and my title
tag is written as
title?php echo $title; ? /title however the title tag remains the same
whether i click web development or software link. how change i change the
code to display different titles.

i am doing this for SEO purpose so that different pages have different
titles and meta tags.

actually there can be indivdual files with links to individual pages however
the people i am dealing with who developed the website want the header and
footer to remain so that a flash file does not have to load each time an
indivdual link is clicked.

please advice.

thanks