You are here: Re: open or output the script with arguments « PHP Programming Language « IT news, forums, messages
Re: open or output the script with arguments

Posted by bobo on 02/01/08 16:24

Rik Wasmus wrote:

> On Fri, 01 Feb 2008 16:35:13 +0100, bobo <fourtwentybh@yahoo.com>
> wrote:
>
> > Rik Wasmus wrote:
> >
> >> On Fri, 01 Feb 2008 15:58:41 +0100, bobo <fourtwentybh@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

--

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация