Including a page w/ GET arguments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • IWP506@gmail.com

    Including a page w/ GET arguments

    Hi

    I have a page that returns data based on the arguments provided to it
    in the URL. I want to show these results embedded in another page.
    Include('mypage .php?name=joe') fails with "failed to open stream:
    Invalid argument". How can I do this?

    Thanks

    IWP506

  • Jerry Stuckle

    #2
    Re: Including a page w/ GET arguments

    IWP506@gmail.co m wrote:[color=blue]
    > Hi
    >
    > I have a page that returns data based on the arguments provided to it
    > in the URL. I want to show these results embedded in another page.
    > Include('mypage .php?name=joe') fails with "failed to open stream:
    > Invalid argument". How can I do this?
    >
    > Thanks
    >
    > IWP506
    >[/color]

    The file name is not 'mypage.php?nam e=joe', is it? That is, do you see
    that in your directory listing?

    When you use GET parameters, the web server strips them out before
    fetching the file. include() does not such thing.

    Include just copies the included file into the location in your existing
    file, just as if you had cut and pasted it. So, if you have:

    $name='joe';
    include('mypage .php');

    Within mypage. php you can just reference $name and get 'joe'.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Andy Jeffries

      #3
      Re: Including a page w/ GET arguments

      On Mon, 13 Mar 2006 23:23:40 -0500, Jerry Stuckle wrote:[color=blue]
      > The file name is not 'mypage.php?nam e=joe', is it? That is, do you see
      > that in your directory listing?
      >
      > When you use GET parameters, the web server strips them out before
      > fetching the file. include() does not such thing.
      >
      > Include just copies the included file into the location in your existing
      > file, just as if you had cut and pasted it. So, if you have:
      >
      > $name='joe';
      > include('mypage .php');
      >
      > Within mypage. php you can just reference $name and get 'joe'.[/color]

      You're probably better off adding name to $_GET so the same code
      can work regardless of which way mypage.php is being called (on it's own
      or through this page).

      $_GET['name'] = 'joe';
      include('mypage .php');

      Or (just for completeness, it's slower) you could do:

      include("http://myhostname/mypage.php?name =joe");

      (this involves apache so would register an extra hit on your site and be
      slower as it would involve a separate PHP instance).

      Cheers,


      Andy


      --
      Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
      http://www.gphpedit.org | PHP editor for Gnome 2
      http://www.andyjeffries.co.uk | Personal site and photos

      Comment

      • Chuck Anderson

        #4
        Re: Including a page w/ GET arguments

        IWP506@gmail.co m wrote:
        [color=blue]
        >Hi
        >
        >I have a page that returns data based on the arguments provided to it
        >in the URL. I want to show these results embedded in another page.
        >Include('mypag e.php?name=joe' ) fails with "failed to open stream:
        >Invalid argument". How can I do this?
        >
        >Thanks
        >
        >IWP506
        >
        >
        >[/color]
        As has been said, you simply do not need add the variable. It is already
        in the local environment and the include file can access it directly.

        Read the first note (and example) here about variable scope:


        --
        *************** **************
        Chuck Anderson • Boulder, CO

        Integrity is obvious.
        The lack of it is common.
        *************** **************

        Comment

        Working...