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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.