473,378 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

PHP 5 Includes are not working

113 100+
Hi there,

I am trying to include a php file with an argument and having rather alot of trouble with it.

This is my code:

include_test.php?storeID=22

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  // File to include into
  3.  session_start();
  4.  include_once("http://website.com/echo.php?storeID=".$_GET['storeID']);
  5. ?>
  6.  
echo.php

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  echo "hello" . $_GET['storeID'];
  3. ?>
  4.  
I get the following error though:
Expand|Select|Wrap|Line Numbers
  1. Warning: include_once(http://threebox.turntool.com/coventgarden/functions/js/echo.php?storeID=22) [function.include-once]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in c:\Inetpub\wwwroot\website.com\include_test.php on line 3
  2.  
  3. Warning: include_once() [function.include]: Failed opening 'http://website.com/echo.php?storeID=22' for inclusion (include_path='.;c:\php\includes;c:\Inetpub\wwwroot\website.com\') in c:\Inetpub\wwwroot\website.com\include_test.php on line 3
  4.  
I have enabled fopen wrappers to see if that would help but it didnt. I've also added a new include dir to the include_path in php.ini and the correct php.ini is being displayed in phpinfo().

I've also tryed to include the file like this:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  // File to include into
  3.  session_start();
  4.  include_once("echo.php?storeID=".$_GET['storeID']);
  5. ?>
  6.  
That doesn't work either, any ideas?
I'm running PHP 5 in ISAPI mode on IIS.

Thanks,

Chromis


-
Jan 29 '08 #1
7 2744
nathj
938 Expert 512MB
Hi,

Whenever I want to do something like this I don't bother with the query string on the end of the URL as like you I've never got that to work and I don't know if it's supposed to work.

What I do is to simply define the variables I want to use before I issue the include. The include effectively sucks all the code into the position where the include line is and so the variables are available.

Psuedo Code
[php]
$Var1 = "TestVar1";
$var2 = 3 ;
include("include/testpage.php") ;
//rest of file
[/php]

In the included file you can simply use these as $var1 and $var2.

I hope this helps you out
Cheers
nathj
Jan 29 '08 #2
chromis
113 100+
Hi NathJ,

Thanks for your help that definately works now. I would be still interested to know if anyone else has got it to work in this particular way?

Thanks again,

Chromis
Jan 29 '08 #3
nathj
938 Expert 512MB
Hi NathJ,

Thanks for your help that definately works now. I would be still interested to know if anyone else has got it to work in this particular way?

Thanks again,

Chromis
Hi Chromis,

I'm glad it's working for you, I am also interested to know if anyone else has made it work in the way you outlien - an included file with a query string. I think the issue is that the include reads the whole thing as the file name and as the file name doesn't include a query string the function fails because it can't find the file.

That's my understanding of it - but I'm keen to hear if anyone else knows differently.

Cheers
nathj
Jan 29 '08 #4
Markus
6,050 Expert 4TB
Hi Chromis,
I think the issue is that the include reads the whole thing as the file name and as the file name doesn't include a query string the function fails because it can't find the file.
That makes sense to me, it searchers for the file you specify including whatever params you add to the file name.
Jan 29 '08 #5
zotrik
1
Hi,

Thanks, it helped me.

There's only one thing I don't understand; on PHP 4 if you write something like:

include 'file.php' . $_SERVER['QUERY_STRING'];

it actually works... I wonder...

But it all makes sense that it doesn't work because of the file extension on PHP 5
Jun 27 '10 #6
Dormilich
8,658 Expert Mod 8TB
include/require are not functions, but language constructs, thus they may be called without parentheses.

From the Manual:
Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value.
Jun 27 '10 #7
Markus
6,050 Expert 4TB
@zotrik
I highly doubt that it works.

As I have said before in this thread, whatever you pass to include*, require*, etc., is what is looked for on the file system. That is, if, you pass it "/var/www/includes/file.php?var1=10" it will look for that exact file name, including the '?var=10'. Ergo, unless that file *does* exist on your system, it won't work as expected.
Jun 27 '10 #8

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

Similar topics

0
by: Yannick Turgeon | last post by:
Hello all, We are currently changing our web server and, in the process, updating PHP version from 4.3.0 to 4.3.5. The problem we've got is that our way to include some files in other ones is no...
11
by: Yannick Turgeon | last post by:
Oups! I did a typing error in my last post. Fixed. ----------- Hello all, We are currently changing our web server and, in the process, updating PHP version from 4.3.0 to 4.3.5. The problem...
2
by: Mike | last post by:
Hello, I'm working on a new site that has a nearly empty index file (variable location) that includes a template file (set location) which in turn includes two data files (variable location...
7
by: jason | last post by:
I am getting twisted by the possibility that my virtual includes which currently work great on non-domain remote IP will crash if I purchase a domain and point it to one of my designated...
0
by: Martin Walke | last post by:
Hi guys, For those who responded before here's an update from hell!!! I think I confused people before when I said on the 'page load' and Chris suggested using the body onload. I was using the...
10
by: Chris Gordon-Smith | last post by:
I am currently revisiting the code of a C++ application and restructuring the code where appropriate to make it consistent with the overall logical design. As part of this, I am looking at the...
8
by: Jim | last post by:
Hi: Do we have some common style for includes when working on a project with lots of c and h files. Wat I mean is do we have a rule in C when a file includes several files and those file in turn...
1
by: Martin Olson | last post by:
is there a way to get the WebDev.WebServer for VS2005 to process server side includes??? thanks for your help on this, mo
2
by: lkrueger | last post by:
Hello-- I have an .html page that I'm trying to use a SSI (footer) and other headers, but it's not showing up. I've tried multiple combinations, but nothing is working. I understand the...
6
by: MaiyaHolliday | last post by:
Hello, I've recently installed apache on a new computer, and cannot figure out why my site will not process any includes. (it was working on my old one) There are no errors on the page such as...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.