Jump to content

Include and passing a variable


xcandiottix

Recommended Posts

<!--#include virtual="/includes/general/artdirector.php?position=top&&page=main" --> works on .HTML page

<?php include('../includes/general/artdirector.php?position=top');?> doesn't work on .PHP page

 

Is there a way to pass the variable "position" to artdirector.php from the .php page?

 

 

edit => <?php include('../includes/general/artdirector.php');?> works on .PHP page, but need to pass variable 'position' none the less

Link to comment
https://forums.phpfreaks.com/topic/208804-include-and-passing-a-variable/
Share on other sites

No, i'm not trying to redirect the user .. I am trying to include the artdirector.php page into another php page. The artdirector.php needs to know whether this include is at the top or bottom of a page. So, I'm trying to pass along where this include resides. artdirector.php then loads art work to the current viewed php page based on the position variable.

That's not what the OP wants.

 

Since the file you're including is not a URL, you can't pass in a value with the file. But since the file is just being executed in the same scope as the main core, just set the variable before you include the file:

 

<?php
$position = 'top';
include('../includes/general/artdirector.php');
?>

 

Ken

Thanks ken, that put me in the right direction but also caused a problem. On the html page I use position=top at the top and position=bottom at the bottom. The top and bottom image sets show correctly. Using your method on the php page causes the top and bottom image sets to both be displayed at the top and the bottom:

 

php page:

top image set

bottom image set

 

 

top image set

bottom image set

 

 

Is there a way to fix this?

index.html

<!--#include virtual="/includes/general/artdirector.php?position=top&&page=main" -->
---html---
<!--#include virtual="/includes/general/artdirector.php?position=bottom&&page=main" -->

 

people.php

<?php 
$position = 'top';
include('../includes/general/artdirector.php');?>
---html data---
<?php 
$position = "bottom";
include('../includes/general/artdirector.php');?>

 

artdirector.php

<?php
if($_GET['page'] == "main"){
session_save_path("/html/tmp/");
session_start();
}
if(isset($_SESSION['active'])){
if($_GET['position'] || $position == "top"){
	require_once('/html/includes/member/Logo-and-Banner-User-UP.html');
}
if($_GET['position'] || $position == "bottom"){
	require_once('/html/includes/member/Mlowernavbar.html');	
}
}
else{
if($_GET['position'] || $position == "top"){
	require_once('/html/includes/general/logobanner.html');
   		require_once('uppernavbar.html');
}
if($_GET['position'] || $position == "bottom"){
	require_once('/html/includes/member/general/lowernavbar.html');
}
}
?>

 

Thanks!

I noticed I said that the images are doubling up on the php page by mistake. Actually, on the PHP page the includes work perfectly. The problem is on the HTML page.

 

<!--#include virtual="/includes/general/artdirector.php?position=top&&page=main" -->

 

makes the top and bottom code to fire in both locations on the HTML page. Sorry I confused that.

DUH!  :'(

if($_GET['position']  || $position == "bottom"){

is wrong because it fires if get position exists. Stupid me.. fix is:

if($_GET['position'] == "bottom" || $position == "bottom"){

 

Thanks for the help ken, i derailed myself =p

Archived

This topic is now archived and is closed to further replies.

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