Jump to content


Photo

Passing variables to included file (PHP 5) **SOLVED**


  • Please log in to reply
2 replies to this topic

#1 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 03 August 2006 - 08:37 AM

Hi,

I'm trying to pass a variable to an included file, that would choose the page.  the variables are pre-set to make the header, menu and include a php file.  This file is included within the index.php file.

I've tried placing $_GET["p"]= $p; in both init.php and index.
(I even have the variable echoing with a string and It is not showing a value.) 

Your help would be appreciated.

Thanks,
Chris

index.php - basically is a wrapper (Like IPB, for example)
<?php

//Index PHP File
//Written by Chris Love
//Revision Date: 08/03/06

//include conf and init
require_once './conf_global.php';
require_once './init.php';

//define vars
$_GET["p"] = $p;

?>

init.php (initializes basic variables and page selection)
<?php

//Init PHP File
//Written by Chris Love
//Revision Date: 08/03/06

//APP Configs
//Added 08/03/06
define( 'ROOT_PATH', dirname( __FILE__ ) ."/" );

//IN DSLR
//Added 08/03/06
define ( 'IN_DSLR', 1 );

//DSLR INIT DONE
//Added 08/03/06
define ( 'DSLR_INIT_DONE', 1 );

//include layout and classes
require_once ROOT_PATH . 'sources/layout/layout.php';
require_once ROOT_PATH . 'sources/classes/class.list.php';

//check if site closed
//Last Mod 08/03/06
echo "the var p = ".$p;
if($pageMaintenance != '0') $p = "maint";
else { $p = "idx"; }

if( $p == "idx" ) {    
    dslrHeader("DSLR-Photography : Digital SLRs, Photography and Imaging");
    dslrMenu();
    include ROOT_PATH . 'sources/include/main.php';
}
elseif ( $p == "news" ) {
    dslrHeader("DSLR-Photography : News");
    dslrMenu();
    include ROOT_PATH . 'sources/include/news.php';
}
elseif ( $p == "links" ) {
    dslrHeader("DSLR-Photography : Links");
    dslrMenu();
    include ROOT_PATH . 'sources/include/links.php';
}
elseif ( $p == "about" ) {
    dslrHeader("DSLR-Photography : About Us");
    dslrMenu();
    include ROOT_PATH . 'sources/include/about.php';
}
elseif ( $p == "maint" ) {
    dslrHeader("DSLR-Photography.com : Site Maintenance");
    include ROOT_PATH . 'sources/include/maint.php'; 
}
else {
    dslrHeader("DSLR-Photography : Error");
    dslrMenu();
    include ROOT_PATH . 'sources/include/error.php';
}
footer();

?>

Chris

#2 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 03 August 2006 - 10:40 AM

Does the variable need to be:

$_GET["p"] = $p; or $p = $_GET["p"]; or do both the same?

Does the variable (in PHP5) usually continue to an included file?
Chris

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 10:50 AM

when including an a file (include / require)
the code from that file is added when it is called

so if you have an include called includeme.php containg

echo $myname;

then your script you have the following code

$myname = "jamie";
include("includeme.php");

this will output
jamie
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users