473,322 Members | 1,610 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,322 software developers and data experts.

Is it possible to pass a variable to a PHP script from inside another PHP piece of code?

Hi. Sorry for what is perhaps a neophyte question: is it possible to
pass a variable to a PHP script from inside another PHP piece of code?

For instance, the file test.php (which of course resides on a
webserver that supports PHP) is as such:

[some HTML code...]
<?php
echo("<i>the variable abc contains " . $_GET['abc'] . "</i>");
?>
[some more HTML code...]

and if I open this file directly i.e. by typing test.php?abc=888 in
the URL line of a web browser, I correctly get the message "the
variable abc contains 888" in italic, surrounded by the HTML content.

Now, let's say that I want to include all this content in another
file, index.php.
I tried to call it as such in index.php

[other HTML...]
<?php
include "test.php?abc=888";
?>
[yet other HTML...]

which is not the correct way as it gives the following error:

Warning: main(l/test.php?abc=888) [function.main]: failed to open
stream: No such file or directory in /home/www/index.php on line 52
Warning: main() [function.include]: Failed opening 'l/test.php?
abc=888' for inclusion (include_path='.:/usr/share/php:/usr/share/
pear') in /home/www/index.php on line 52

How should I call the file?
Thanks in advance for any hint!

Oct 27 '07 #1
3 1813
The file is l/test.php of course.

Oct 27 '07 #2
On Sat, 27 Oct 2007 23:44:56 +0200, le***********************@gmail.com
<le***********************@gmail.comwrote:
Hi. Sorry for what is perhaps a neophyte question: is it possible to
pass a variable to a PHP script from inside another PHP piece of code?

For instance, the file test.php (which of course resides on a
webserver that supports PHP) is as such:

[some HTML code...]
<?php
echo("<i>the variable abc contains " . $_GET['abc'] . "</i>");
?>
[some more HTML code...]

and if I open this file directly i.e. by typing test.php?abc=888 in
the URL line of a web browser, I correctly get the message "the
variable abc contains 888" in italic, surrounded by the HTML content.

Now, let's say that I want to include all this content in another
file, index.php.
I tried to call it as such in index.php

[other HTML...]
<?php
include "test.php?abc=888";
?>
[yet other HTML...]

which is not the correct way as it gives the following error:

Warning: main(l/test.php?abc=888) [function.main]: failed to open
stream: No such file or directory in /home/www/index.php on line 52
Warning: main() [function.include]: Failed opening 'l/test.php?
abc=888' for inclusion (include_path='.:/usr/share/php:/usr/share/
pear') in /home/www/index.php on line 52

How should I call the file?
Thanks in advance for any hint!
The $_GET array is available to all scipts, _provided_ you use the file
system to include the file, and not by http some newcomers seem to do. So:

URL:
test.php?foo=bar

test.php:
<?php
$check = 'hello';
include './include.php';
?>

include.php
<?php
var_dump($_GET);
echo $check;
?>

... will correctly show the $_GET array and the $check variable.
--
Rik Wasmus
Oct 27 '07 #3
Thanks a lot for these very useful and quick answers!

Oct 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jan Pieter Kunst | last post by:
(apologies if this message is a duplicate -- my news server seems to have problems) Greetings, When using PHP 4, this: // ex. 1 class A { function A(&$obj) {
6
by: Chris Lasher | last post by:
Hello, I would like to create a set of very similar regular expression. In my initial thought, I'd hoped to create a regular expression with a variable inside of it that I could simply pass a...
4
by: frogman042 | last post by:
My daughter is playing around trying to learn JavaScript and she wrote a small program that prints out a message in increasing and decreasing font size and color changes. She is using document...
8
by: Daniel | last post by:
Hi, Does anyone know if it is possible to put an aspx page inside of another? OR run an aspx page and capture the output as a string and then write this out to a page.... So for example say...
2
by: Daz | last post by:
Hi everyone. Sorry for the confusing subject, I couldn't think how best to word it. What I would like to know, is if there is an equivilant to this code, in using JSON. <script...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
4
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.