include a file with parameters

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
What i want to do is the following:

include (pagecalled.php?argument1=x&argument2=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 '';

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

Re: include a file with parameters

julian maisano wrote:
Quoted text here. Click to load it

How about this:

$argument1 = x;
$argument2 = x;


Re: include a file with parameters

Peter van Schie wrote:
Quoted text here. Click to load it

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

regards - julian

Re: include a file with parameters

julian_m wrote:

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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.


Re: include a file with parameters

Quoted text here. Click to load it

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

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.php?arg=hello>Say 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).


Site Timeline