Jump to content

[SOLVED] Get arguments in include function.


BillyBoB
 Share

Recommended Posts

I have a site I have been working on for a while now... I recently switched servers for this site only and the includes that have the extra arguments, ex: www.site.com/index.php?arg=anwser, are failing.

 

Warning:  include_once(./includes/Navigation.php?curpg=Home) [function.include-once]: failed to open stream: No such file or directory in /home/game/public_html/Home on line 58

 

Anyone have any ideas?

Link to comment
Share on other sites

<?php
$_GET['curpg'] = "Home";
   if($logged==true) {
      $_GET['lgdusr'] = true;
   }
      include_once("./includes/Navigation.php");
?>

 

Will work. If it worked on your other server, they must of allowed it or had a function to parse out the get variables. I have never seen that work for server-side files in my time.

Link to comment
Share on other sites

no arguemtn can be passed through include without the full url

 

include_once("./includes/Navigation.php?arug=foo");

 

Is your server looking for a file called Navigation.php?arug=foo not a file called Navigation.php and passing the arguments

Link to comment
Share on other sites

@premiso:

That will not work because I am sending the argument to the Navigation page. That way it will highlight the correct tab. It is for dynamic navigation.

 

That is doing the exact thing you were trying to do, it is sending GET variables, using the ? & etc sends the get variables in a regular url.

 

So if that does not work, maybe your new server as register_globals off and you were accessing the variables not using $_GET?

 

That is the only explanation I can give. The above works fine with this script:

 

index.php

<?php
include('page.php?id=3&user=jack');
?>

 

page.php

<?php
echo $_GET['id'] . ' is ' . $_GET['user'] . '\'s user id!';
?>

 

Should print out 4 is jack's user id!  when index.php is called.

Link to comment
Share on other sites

@BillyBoB

 

maybe you should read the example before you quote it

 


// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';

// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';

// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';

 

It says that it won't work!

Link to comment
Share on other sites

Moral of the story: You CANNOT send true GET variables to a locally included file because you aren't actually using an HTTP GET request for it, therefore Apache won't parse a request and send any variables to PHP.  Just set the variables before you include the file.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.