473,837 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems passing variables to include file.

14 New Member
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["directoryl ist"]; // (Which I split to get the correct path to the image)
[/PHP]
Nov 3 '08 #1
5 9597
Markus
6,050 Recognized Expert Expert
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
harryusa
14 New Member
file1.php
[PHP]
define("IMAGENU MBERCONST",$_GE T["imagenumbe r"]);[/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("sessio n.cookie_domain ",substr($_SERV ER[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 IMAGENUMBERCONS T;
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 IMAGENUMBERCONS T is a literal.
Nov 3 '08 #3
harryusa
14 New Member
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 Recognized Expert Expert
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 Recognized Expert Top Contributor
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
4997
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" and all users in the db are presented in a table. The first column 'Pnr' is a unique ID for each user that i made appear as a link. clicking on one userID should present a form where the picked users userdata is already filled in so i can easily edit it and then move on to submit the form to...
3
14968
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. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
9
2597
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 file phead.h I have two code files main.cpp and gameloop.cpp phead.h has all my core declarations in it like my main globals. main.cpp has all my window initilization functions and my winproc loop.
1
1755
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: <?php ob_start(); include('/home/mysite/public_html/cgi-bin/usersonline/online.cgi'); $contents = ob_get_contents(); ob_end_clean();
5
2541
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 and copies the contents into the two char*s. Now when my function returns, the values stored in the char* are some garbage values (perhaps because I didn't allocate any memory for them).. but even if I allocate memory in the function, on the return of this function I see garbage.. here is my...
1
6797
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 $_GET variables, but I don't know how to do this for the $_POST ones. Thank you all! Matthew
3
2414
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 Shore</h3></a><br> These go to a php web page and are used thusly. <?php include ($_SERVER); ?//this is line 3 <?php include ($_SERVER); ?// line 5
2
3280
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 for latter searching. I am trying to use structres and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
10
1889
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 program that prints out a square or rectangle using the * character. The program was just for practice but I am having problems. My main problem is, in my program I use 4 functions to change or access two variables in my code. The variables are
0
9830
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10864
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10562
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10615
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10263
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4469
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4036
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.