open or output the script with arguments

open or output the script with arguments

am 01.02.2008 15:06:34 von bobo

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

--

Re: open or output the script with arguments

am 01.02.2008 15:15:35 von Franz Marksteiner

bobo wrote:
> 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

Just set the desired output in a switch, and perform the output...

switch($_GET['id']){
case 1:
$myOutput = 'first test';
break;
case 2:
$myOutput = 'second test';
break;
}

echo $myOutput;
--
Freundliche Grüße,
Franz Marksteiner

Re: open or output the script with arguments

am 01.02.2008 15:28:49 von bobo

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
--

Re: open or output the script with arguments

am 01.02.2008 15:58:41 von bobo

I need something like include("first.php?id=1")...

--

Re: open or output the script with arguments

am 01.02.2008 16:06:29 von luiheidsgoeroe

On Fri, 01 Feb 2008 15:58:41 +0100, bobo wrote:=


> I need something like include("first.php?id=3D1")...
>

You don't. $_GET variables are available in the included script:


URL: first.php?id=3D2
first.php
include 'second.php';
?>
second.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=3D2
first.php
$id =3D 3;
include 'second.php';
?>
second.php
$id =3D isset($id) ? $id : $_GET['id'];
echo $id;//outputs '3'
?>
-- =

Rik Wasmus

Re: open or output the script with arguments

am 01.02.2008 16:12:56 von Captain Paralytic

On 1 Feb, 14:06, "bobo" wrote:
> 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
>
> --

One thing that is I think confusing people is your use of the word
"output". A script may output something (usually by means of an echo
statement). Scripts may be called by invoking them through a web
server via a URL, containing the arguments that you suggest (e.g. ?
id=1) or maybe on the command line.

When you include a script, you are just getting the contents into the
script you are currently executing. So if the script you are including
wants to find something in the $_GET array, put it in there before you
include it. However, it feels that you should really be coding using
classes or at least functions for this job.

Re: open or output the script with arguments

am 01.02.2008 16:35:13 von bobo

Rik Wasmus wrote:

> On Fri, 01 Feb 2008 15:58:41 +0100, bobo
> 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
> > include 'second.php';
> ?>
> second.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
> > $id = 3;
> include 'second.php';
> ?>
> second.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.

but... without the link... something like include

is that possible?
--

Re: open or output the script with arguments

am 01.02.2008 16:37:41 von Franz Marksteiner

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

Re: open or output the script with arguments

am 01.02.2008 16:50:50 von luiheidsgoeroe

On Fri, 01 Feb 2008 16:35:13 +0100, bobo wrote:=


> Rik Wasmus wrote:
>
>> On Fri, 01 Feb 2008 15:58:41 +0100, bobo
>> wrote:
>>
>> > I need something like include("first.php?id=3D1")...
>> >
>>
>> You don't. $_GET variables are available in the included script:
>>
>>
>> url: first.php?id=3D2
>> first.php
>> >> include 'second.php';
>> ?>
>> second.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=3D2
>> first.php
>> >> $id =3D 3;
>> include 'second.php';
>> ?>
>> second.php
>> >> $id =3D 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=3D1")
>
> 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.
>

> but... without the link... something like include
>
> is that possible?

Offcourse, you could include by HTTP instead of the FILE system, and giv=
e =

GET variables. This has all sorts of drawbacks, and I wouldn't recommend=
=

it.

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

I'd opt for the second option every time.
If you're worried about variables in global scope:
first.php
function second_include($args){
extract($args);
include('second.php');
}
second_include(array('foo' =3D> 'bar'));
?>
second.php

-- =

Rik Wasmus

Re: open or output the script with arguments

am 01.02.2008 17:01:40 von Jerry Stuckle

bobo wrote:
> Rik Wasmus wrote:
>
>> On Fri, 01 Feb 2008 15:58:41 +0100, bobo
>> 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
>> >> include 'second.php';
>> ?>
>> second.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
>> >> $id = 3;
>> include 'second.php';
>> ?>
>> second.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.
>

> 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.
jstucklex@attglobal.net
==================

Re: open or output the script with arguments

am 01.02.2008 17:09:58 von Rob

On Feb 1, 2:06=A0pm, "bobo" wrote:
> 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=3D1
>
> 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=3D1
> and to get -> first test
> and if I output first.php?id=3D2
> 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 :-


function second_function($id) {
.....
do_something_with_id;
.....
}


Rob.

Re: open or output the script with arguments

am 01.02.2008 17:24:57 von bobo

Rik Wasmus wrote:

> On Fri, 01 Feb 2008 16:35:13 +0100, bobo
> wrote:
>
> > Rik Wasmus wrote:
> >
> >> On Fri, 01 Feb 2008 15:58:41 +0100, bobo
> >> 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
> >> > >> include 'second.php';
> >> ?>
> >> second.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
> >> > >> $id = 3;
> >> include 'second.php';
> >> ?>
> >> second.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.
> >

> > 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:
> > include('http://www.example.com/foo.php?id=1');
> ?>
> ... is easier for you then:
> > $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
> > function second_include($args){
> extract($args);
> include('second.php');
> }
> second_include(array('foo' => 'bar'));
> ?>
> second.php
>

thx... I am doing this like that... just thought... maybe it could be
done in a antoher way...

thx

--