Jump to content

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


Cell0518

Recommended Posts

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)
[code]<?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;

?> [/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/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();

?> [/code]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.