Jump to content

[SOLVED] Get arguments in include function.


BillyBoB

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?

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

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

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

@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!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.