Author Topic: [SOLVED] Get arguments in include function.  (Read 1490 times)

0 Members and 1 Guest are viewing this topic.

Offline BillyBoBTopic starter

  • Devotee
  • All who have helped me, will be helped later.
    • View Profile
    • :) CLICK CLICK CLICK :)
[SOLVED] Get arguments in include function.
« on: December 08, 2008, 06:23:59 PM »
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?

Online thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
    • View Profile
Re: Get arguments in include function.
« Reply #1 on: December 08, 2008, 06:32:51 PM »
Of course it fails, you can't pass arguments to an include unless you are calling them via a url. And then they don't execute within the same process.

Can we see how you make this call to include_once?

Offline BillyBoBTopic starter

  • Devotee
  • All who have helped me, will be helped later.
    • View Profile
    • :) CLICK CLICK CLICK :)
Re: Get arguments in include function.
« Reply #2 on: December 08, 2008, 06:48:22 PM »
I don't see how it wouldn't work because it was working fine on my other server.

Code: [Select]
<?php
if(
$logged==true) {
include_once("./includes/Navigation.php?curpg=Home&lgdusr=true");
}else{
include_once("./includes/Navigation.php?curpg=Home");
}
?>


Offline premiso

  • Life is too short
  • Freak!
  • Gender: Male
  • No one cares.
    • View Profile
    • Help Source for Coders
Re: Get arguments in include function.
« Reply #3 on: December 08, 2008, 06:50:30 PM »
Code: [Select]
<?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.
« Last Edit: December 08, 2008, 06:51:03 PM by premiso »

Offline gevans

  • Addict
  • Gender: Male
  • don't shoot the messanger
    • View Profile
    • Purple Coffee Interactive
Re: Get arguments in include function.
« Reply #4 on: December 08, 2008, 06:53:21 PM »
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
I like starting my code with session_start();

Code: [Select]
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
Son of a biscuit eating bulldog

Use [code][/code] tags!!

Offline BillyBoBTopic starter

  • Devotee
  • All who have helped me, will be helped later.
    • View Profile
    • :) CLICK CLICK CLICK :)
Re: Get arguments in include function.
« Reply #5 on: December 08, 2008, 06:53:56 PM »
@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.

Offline premiso

  • Life is too short
  • Freak!
  • Gender: Male
  • No one cares.
    • View Profile
    • Help Source for Coders
Re: Get arguments in include function.
« Reply #6 on: December 08, 2008, 06:58:35 PM »
@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
Code: [Select]
<?php
include('page.php?id=3&user=jack');
?>


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


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

Offline BillyBoBTopic starter

  • Devotee
  • All who have helped me, will be helped later.
    • View Profile
    • :) CLICK CLICK CLICK :)
Re: Get arguments in include function.
« Reply #7 on: December 08, 2008, 07:04:06 PM »
@gevans:
http://us2.php.net/include/
Example #3.

premiso your first suggestion worked just took a second to test.
« Last Edit: December 08, 2008, 07:12:31 PM by BillyBoB »

Offline gevans

  • Addict
  • Gender: Male
  • don't shoot the messanger
    • View Profile
    • Purple Coffee Interactive
Re: Get arguments in include function.
« Reply #8 on: December 08, 2008, 07:15:27 PM »
@BillyBoB

maybe you should read the example before you quote it

Code: [Select]

// 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!
I like starting my code with session_start();

Code: [Select]
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
Son of a biscuit eating bulldog

Use [code][/code] tags!!

Offline DarkWater

  • Freak!
  • Gender: Male
    • View Profile
Re: Get arguments in include function.
« Reply #9 on: December 08, 2008, 07:17:34 PM »
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.
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.
Quote from: Crayon Violent
If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.