472,780 Members | 1,200 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 1767
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....
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.