include a file with parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • julian maisano

    include a file with parameters

    What i want to do is the following:

    include (pagecalled.php ?argument1=x&ar gument2=x ..... );

    (I need to place the page somewhere inside another one, as if it had
    been called from another link)

    Doesn't work this way, but it works providing full path

    include 'www.somesite.c om/dir1/dir2/pagecalled.php? argument1=x&arg ument2=x';

    As you can see, it would be better without full path, in order to be
    able to change server without code rewrite.

    Is there any way to solve that situation?

    sdos - jm
  • Peter van Schie

    #2
    Re: include a file with parameters

    julian maisano wrote:[color=blue]
    > What i want to do is the following:
    >
    > include (pagecalled.php ?argument1=x&ar gument2=x ..... );
    >[/color]

    How about this:

    $argument1 = x;
    $argument2 = x;
    include('pageca lled.php');

    --

    Comment

    • julian_m

      #3
      Re: include a file with parameters



      Peter van Schie wrote:[color=blue]
      > julian maisano wrote:[color=green]
      > > What i want to do is the following:
      > >
      > > include (pagecalled.php ?argument1=x&ar gument2=x ..... );
      > >[/color]
      >
      > How about this:
      >
      > $argument1 = x;
      > $argument2 = x;
      > include('pageca lled.php');
      >
      > --
      > http://www.phpforums.nl[/color]


      Will pagecalled.php "see" both $argument1 and $argument2? How?
      If so, why do we use this way: pagecalled.php? argument1=x&arg ument2=x?
      Is it just an option to do the same?


      regards - julian

      Comment

      • Peter van Schie

        #4
        Re: include a file with parameters

        julian_m wrote:
        [color=blue]
        > Will pagecalled.php "see" both $argument1 and $argument2? How?[/color]

        Yes, because include() basically just inserts the code from
        pagecalled.php at the position of the include call. Therefore the
        $argument1 and $argument2 variables are available to the code in
        pagecalled.php if you set them like this.
        [color=blue]
        > If so, why do we use this way: pagecalled.php? argument1=x&arg ument2=x?
        > Is it just an option to do the same?[/color]

        No, it's not the same. You're talking about the HTTP GET method to send
        data to a script from a html form, for instance data a user submitted
        using a html form.

        In your case you just want to be able to use php variables in a php
        script you include from another php script.

        --

        Comment

        • luke

          #5
          Re: include a file with parameters

          > > > What i want to do is the following:[color=blue][color=green][color=darkred]
          > > >
          > > > include (pagecalled.php ?argument1=x&ar gument2=x ..... );
          > > >[/color]
          > >
          > > How about this:
          > >
          > > $argument1 = x;
          > > $argument2 = x;
          > > include('pageca lled.php');
          > >
          > > --
          > > http://www.phpforums.nl[/color]
          >
          >
          > Will pagecalled.php "see" both $argument1 and $argument2? How?
          > If so, why do we use this way: pagecalled.php? argument1=x&arg ument2=x?
          > Is it just an option to do the same?[/color]

          It will 'see' the variables the same way any code written after those
          variables were declared could see them - a PHP 'include('');' takes the file
          and mixes it in, almost like a copy and paste job of the file contents. Give
          it a go, you'll notice it works.

          Appending variables onto the URL is a method of sending variables across
          pages, it is called 'GET' and another method is called 'POST' - have a read
          at php.net.

          To demonstrate GET, try this code by itself:

          <?php echo $_GET['arg']; ?>

          Now view the webpage and append ?arg=hello onto the end of the URL. You can
          change arg to equal anything and it will display on the page.

          Usually you wouldn't use GET unless you needed to, because the whole world
          can see your variables in the address bar, and therefor can reassign them by
          editing the URL. This opens your PHP script up to manipulation. However GET
          is still pretty handy for times when you want to send variables to another
          page through, say, a link, since POST only works through an HTML form. A
          whole row of links like <a href=nextpage.p hp?arg=hello>Sa y Hello</a> but
          with different values for 'arg' - you've only made 1 PHP file called
          nextpage.php, but if it's recieving a $_GET['arg'] value you've got an
          almost limitless amount of different permutations for that page (dynamic).

          Luke









          Comment

          Working...