Cell0518 Posted August 3, 2006 Share Posted August 3, 2006 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,Chrisindex.php - basically is a wrapper (Like IPB, for example)[code]<?php//Index PHP File//Written by Chris Love//Revision Date: 08/03/06//include conf and initrequire_once './conf_global.php';require_once './init.php';//define vars$_GET["p"] = $p;?> [/code]init.php (initializes basic variables and page selection)[code]<?php//Init PHP File//Written by Chris Love//Revision Date: 08/03/06//APP Configs//Added 08/03/06define( 'ROOT_PATH', dirname( __FILE__ ) ."/" );//IN DSLR//Added 08/03/06define ( 'IN_DSLR', 1 );//DSLR INIT DONE//Added 08/03/06define ( 'DSLR_INIT_DONE', 1 );//include layout and classesrequire_once ROOT_PATH . 'sources/layout/layout.php';require_once ROOT_PATH . 'sources/classes/class.list.php';//check if site closed//Last Mod 08/03/06echo "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();?> [/code] Link to comment https://forums.phpfreaks.com/topic/16423-passing-variables-to-included-file-php-5-solved/ Share on other sites More sharing options...
Cell0518 Posted August 3, 2006 Author Share Posted August 3, 2006 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? Link to comment https://forums.phpfreaks.com/topic/16423-passing-variables-to-included-file-php-5-solved/#findComment-68441 Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 when including an a file (include / require)the code from that file is added when it is calledso if you have an include called includeme.php containgecho $myname;then your script you have the following code$myname = "jamie";include("includeme.php");this will outputjamie Link to comment https://forums.phpfreaks.com/topic/16423-passing-variables-to-included-file-php-5-solved/#findComment-68447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.