472,351 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 software developers and data experts.

Problems passing variables to include file.

I don't know why I cannot get this to work. I want to include an external file in a script that produces an HTML table and is populated based on a few variables from the calling script. I thought php compiled in line, but after having no luck I tried executing the script by calling it by itself and it worked correctly filling itself with the correct SESSION variables. Maybe it's my syntax but I have tried Session variables, I think I used global correctly but I am not sure. I need to pass two items,
[PHP]
$imagenumber; // an image number in a variable called
$_SESSION["directorylist"]; // (Which I split to get the correct path to the image)
[/PHP]
Nov 3 '08 #1
5 9536
Markus
6,050 Expert 4TB
If you're including a file, that file inherits the variables of it's parent. Consider this:

file1.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. define("HELLO", "Hello from file1");
  4.  
  5. include("file2.php");
  6.  
  7. ?>
  8.  
and in file2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo HELLO;
  4. // would print: Hello from file1
  5. ?>
  6.  
Nov 3 '08 #2
file1.php
[PHP]
define("IMAGENUMBERCONST",$_GET["imagenumber"]);[/PHP]

And what's going on with the SESSION variable? I initialized my session but it doesn't want to pass the $_SESSION["home"] variable?

include("file2.php");
[PHP]
<? ini_set("session.cookie_domain",substr($_SERVER[HTTP_HOST],3));
session_start();
$_SESSION["home"];
$dirlist = split ('\/', $_SESSION["home"]);

// ***ABBREVIATED******
echo'<img HEIGHT="100", WIDTH="60" src="http://www.website.com/';
echo "$dirlist[1]/$dirlist[2]/tn_";
echo IMAGENUMBERCONST;
echo'">';
?><html>
</table>
[/PHP]
This gives me the incorrect path to the image:
http://www.website.com///tn_IMAGENUMBERCONST
As you can see the directories aren't present and IMAGENUMBERCONST is a literal.
Nov 3 '08 #3
IMPORTANT THING TO REMEMBER ABOUT THE include("xxx"); function!
I was using the URL as a path to call the script when I should have been using the relative server path ie:
[PHP] include("/home/4/4/a/2769/2769/public_html/file2.php"); [/PHP]

NOT [PHP]("http://www.website.com/file2.php");[/PHP]
The relative path works fine for including html for headers and footers and such but I guess all SESSION variables are not available when using this path even if you use [PHP]<? session_start();[/PHP]
Which, by the way, I DID NOT have to use (session_start();)in the included file's head.
Thanks for the insight!
Nov 3 '08 #4
Markus
6,050 Expert 4TB
I don't see the point in using SESSION, as you're not actually leaving the page. But I think I'm not understanding something here..
Nov 3 '08 #5
ak1dnar
1,584 Expert 1GB
could you please first change your include script path
from this:
Expand|Select|Wrap|Line Numbers
  1. include("/home/4/4/a/2769/2769/public_html/file2.php");
to this:
Expand|Select|Wrap|Line Numbers
  1. include("file2.php");
As I can see, you are using a shared hosting server right? (may not be too)
anyway no need to setup your path like /home/.... just give the relative path as i suggested.

let me have a closer look to your problem, as I also not sure about your question.
Nov 3 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Fredrik/Sweden | last post by:
Hi folks ! got this problem... i have a table 'Accounts' in my database, which contains a bunch of users. From the main menu i choose "edit user"...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. ...
9
by: Daniel Moree | last post by:
I'm using MS VC++ 6.0 I'm working on a big project. I've currently have several files for this project. Here's the problem. I have one header...
1
by: VB | last post by:
Dear friends, I have a big problem. With an usersonline script I need to extract in php the output of a cgi using buffering output in this way: ...
5
by: Sona | last post by:
I understand the problem I'm having but am not sure how to fix it. My code passes two char* to a function which reads in some strings from a file...
1
by: Infiliset | last post by:
Hi all! I'm trying to test some php script using the command line php.exe. Is there any way to pass the $_POST variables? I know how to pass the...
3
by: Dave Kelly | last post by:
From a html page menu I need to pass 2 variables. <a href="signup.php?var1=list-PINSS.php&var2=blurb-PINSS.php"><h3>Padre Island National Sea...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory...
10
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.