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

open or output the script with arguments

Hello,
How can I output the file with arguments... i.e
I have a file called first.php
and i have a file called second.php
what I want to do is output the first.php, but with arguments...
something like this
first.php?id=1

and in the first.php I check the id... and run the script depending on
the id... so... if id is 1... it outputs... i.e. 'first test', and if
id is 2, it outputs 'second test'

so... what I want to do is...
output first.php?id=1
and to get -first test
and if I output first.php?id=2
to get -second test

any ideas?

thx

--

Feb 1 '08 #1
9 1420
Franz Marksteiner wrote:

maybe I wasn't clear... I did that in the file second.php... and it
works... when I link to it... but what I want to do is to output the
second.php from first.php... and to execute the second.php while
outputing it

thx
--

Feb 1 '08 #2
I need something like include("first.php?id=1")...

--

Feb 1 '08 #3
On Fri, 01 Feb 2008 15:58:41 +0100, bobo <fo**********@yahoo.comwrote:
I need something like include("first.php?id=1")...
You don't. $_GET variables are available in the included script:
URL: first.php?id=2
first.php
<?php
include 'second.php';
?>
second.php
<?php
echo $_GET['id'];//outputs '2'
?>

Now, if you need the _change_ the GET variable in between, there is
something wrong with the logic, but we can work around that:

URL: first.php?id=2
first.php
<?php
$id = 3;
include 'second.php';
?>
second.php
<?php
$id = isset($id) ? $id : $_GET['id'];
echo $id;//outputs '3'
?>
--
Rik Wasmus
Feb 1 '08 #4
Rik Wasmus wrote:
On Fri, 01 Feb 2008 15:58:41 +0100, bobo <fo**********@yahoo.com>
wrote:
I need something like include("first.php?id=1")...

You don't. $_GET variables are available in the included script:
url: first.php?id=2
first.php
<?php
include 'second.php';
?>
second.php
<?php
echo $_GET['id'];//outputs '2'
?>

Now, if you need the change the GET variable in between, there is
something wrong with the logic, but we can work around that:

url: first.php?id=2
first.php
<?php
$id = 3;
include 'second.php';
?>
second.php
<?php
$id = isset($id) ? $id : $_GET['id'];
echo $id;//outputs '3'
?>

yes... that's what I'm doing now... to set the value for the variable
and then include the second file... but, I was wondering if I could do
a function like include, but add argument to the second file...

something like this

first.php
include("second.php?id=1")

second.php
do whatever, with the id value

so... what I want is not to set the value before... but... to send the
value to the file... something like you use when linking... i.e.
<a href='second.php?id=1'>
but... without the link... something like include

is that possible?
--

Feb 1 '08 #5
bobo wrote:
I need something like include("first.php?id=1")...
You can`t send the GET var this way, but the GET var sent to the first.php
will also be accessable in all included/required files.

--
Freundliche Grüße,
Franz Marksteiner

Feb 1 '08 #6
On Fri, 01 Feb 2008 16:35:13 +0100, bobo <fo**********@yahoo.comwrote:
Rik Wasmus wrote:
>On Fri, 01 Feb 2008 15:58:41 +0100, bobo <fo**********@yahoo.com>
wrote:
I need something like include("first.php?id=1")...

You don't. $_GET variables are available in the included script:
url: first.php?id=2
first.php
<?php
include 'second.php';
?>
second.php
<?php
echo $_GET['id'];//outputs '2'
?>

Now, if you need the change the GET variable in between, there is
something wrong with the logic, but we can work around that:

url: first.php?id=2
first.php
<?php
$id = 3;
include 'second.php';
?>
second.php
<?php
$id = isset($id) ? $id : $_GET['id'];
echo $id;//outputs '3'
?>


yes... that's what I'm doing now... to set the value for the variable
and then include the second file... but, I was wondering if I could do
a function like include, but add argument to the second file...

something like this

first.php
include("second.php?id=1")

second.php
do whatever, with the id value

so... what I want is not to set the value before... but... to send the
value to the file... something like you use when linking... i.e.
<a href='second.php?id=1'>
but... without the link... something like include

is that possible?
Offcourse, you could include by HTTP instead of the FILE system, and give
GET variables. This has all sorts of drawbacks, and I wouldn't recommend
it.

Is there any reason that this:
<?php
include('http://www.example.com/foo.php?id=1');
?>
.... is easier for you then:
<?php
$id=1;
include('foo.php');
?>

I'd opt for the second option every time.
If you're worried about variables in global scope:
first.php
<?php
function second_include($args){
extract($args);
include('second.php');
}
second_include(array('foo' ='bar'));
?>
second.php
<?php echo $foo; ?>
--
Rik Wasmus
Feb 1 '08 #7
bobo wrote:
Rik Wasmus wrote:
>On Fri, 01 Feb 2008 15:58:41 +0100, bobo <fo**********@yahoo.com>
wrote:
>>I need something like include("first.php?id=1")...
You don't. $_GET variables are available in the included script:
url: first.php?id=2
first.php
<?php
include 'second.php';
?>
second.php
<?php
echo $_GET['id'];//outputs '2'
?>

Now, if you need the change the GET variable in between, there is
something wrong with the logic, but we can work around that:

url: first.php?id=2
first.php
<?php
$id = 3;
include 'second.php';
?>
second.php
<?php
$id = isset($id) ? $id : $_GET['id'];
echo $id;//outputs '3'
?>


yes... that's what I'm doing now... to set the value for the variable
and then include the second file... but, I was wondering if I could do
a function like include, but add argument to the second file...

something like this

first.php
include("second.php?id=1")

second.php
do whatever, with the id value

so... what I want is not to set the value before... but... to send the
value to the file... something like you use when linking... i.e.
<a href='second.php?id=1'>
but... without the link... something like include

is that possible?
No, you're not loading a URL, you're reading a file.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Feb 1 '08 #8
Rob
On Feb 1, 2:06*pm, "bobo" <fourtwent...@yahoo.comwrote:
Hello,
How can I output the file with arguments... i.e
I have a file called first.php
and i have a file called second.php
what I want to do is output the first.php, but with arguments...
something like this
first.php?id=1

and in the first.php I check the id... and run the script depending on
the id... so... if id is 1... it outputs... i.e. 'first test', and if
id is 2, it outputs 'second test'

so... what I want to do is...
output first.php?id=1
and to get -first test
and if I output first.php?id=2
to get -second test

any ideas?

thx

--
You question is not wrong, you are just thinking about it the wrong
way.

In first.php :-

include("second.php");
second_function($_GET['id']);
second.php will then look like this :-

<?php

function second_function($id) {
.....
do_something_with_id;
.....
}
Rob.
Feb 1 '08 #9
Rik Wasmus wrote:
On Fri, 01 Feb 2008 16:35:13 +0100, bobo <fo**********@yahoo.com>
wrote:
Rik Wasmus wrote:
On Fri, 01 Feb 2008 15:58:41 +0100, bobo <fo**********@yahoo.com>
wrote:
>
I need something like include("first.php?id=1")...

>
You don't. $_GET variables are available in the included script:
>
>
url: first.php?id=2
first.php
<?php
include 'second.php';
?>
second.php
<?php
echo $_GET['id'];//outputs '2'
?>
>
Now, if you need the change the GET variable in between, there is
something wrong with the logic, but we can work around that:
>
url: first.php?id=2
first.php
<?php
$id = 3;
include 'second.php';
?>
second.php
<?php
$id = isset($id) ? $id : $_GET['id'];
echo $id;//outputs '3'
?>

yes... that's what I'm doing now... to set the value for the
variable and then include the second file... but, I was wondering
if I could do a function like include, but add argument to the
second file...

something like this

first.php
include("second.php?id=1")

second.php
do whatever, with the id value

so... what I want is not to set the value before... but... to send
the value to the file... something like you use when linking... i.e.
<a href='second.php?id=1'>
but... without the link... something like include

is that possible?

Offcourse, you could include by HTTP instead of the FILE system, and
give GET variables. This has all sorts of drawbacks, and I wouldn't
recommend it.

Is there any reason that this:
<?php
include('http://www.example.com/foo.php?id=1');
?>
... is easier for you then:
<?php
$id=1;
include('foo.php');
?>

I'd opt for the second option every time.
If you're worried about variables in global scope:
first.php
<?php
function second_include($args){
extract($args);
include('second.php');
}
second_include(array('foo' ='bar'));
?>
second.php
<?php echo $foo; ?>
thx... I am doing this like that... just thought... maybe it could be
done in a antoher way...

thx

--

Feb 1 '08 #10

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

Similar topics

4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
5
by: Carl Castrianni | last post by:
When running files containing many sql statements using the db2 command line processor, I`d like to have the output show the time that each sql statement was executed (so I know when they ran). ...
5
by: Paul Bergson | last post by:
I have been trying to get a process to start up and run with arguments passed to it. I have gotten close (Thanks to help from this board) but I there is a failure while I'm running this because...
4
by: tony.ha | last post by:
Hello, I have open a Python program in the IDLE, but when I select the "run module" under "run" menu, it does not allow me to pass an argument to my Python program! How do you pass an argument...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.