472,127 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

include a file with parameters

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 'www.somesite.com/dir1/dir2/pagecalled.php?argument1=x&argument2=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
Jul 27 '05 #1
4 18361
julian maisano wrote:
What i want to do is the following:

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


How about this:

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

--
http://www.phpforums.nl
Jul 27 '05 #2


Peter van Schie wrote:
julian maisano wrote:
What i want to do is the following:

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


How about this:

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

--
http://www.phpforums.nl

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

Jul 27 '05 #3
julian_m wrote:
Will pagecalled.php "see" both $argument1 and $argument2? How?
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.
If so, why do we use this way: pagecalled.php?argument1=x&argument2=x?
Is it just an option to do the same?


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.

--
http://www.phpforums.nl
Jul 27 '05 #4
> > > What i want to do is the following:

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


How about this:

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

--
http://www.phpforums.nl

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?


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

Luke



Jul 27 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by middletree | last post: by
6 posts views Thread by qaz | last post: by
10 posts views Thread by Toke H?iland-J?rgensen | last post: by
1 post views Thread by Greg Scharlemann | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.