[solved] <?php include("page.php?var=x");?> gives error

Problems with the Windows version of XAMPP, questions, comments, and anything related.

[solved] <?php include("page.php?var=x");?> gives error

Postby goku87 » 30. May 2010 05:44

Using the include fuction while trying to pass a variable at the same time like this:

Code: Select all
<?php include("button.php?text=home&url=index");?>


Gives me this error code:

Warning: include(button.php?text=home&url=index) [function.include]: failed to open stream: No error in X:\Dir\WebSite\index.php on line 73
Warning: include() [function.include]: Failed opening 'button.php?text=home&url=index' for inclusion (include_path='.;X:\Dir\_xampp\php\PEAR') in X:\Dir\WebSite\index.php on line 73


Google isn't really helping me out. Everything works separately, and even together, except for the include statement. If i remove the ?text... at the end then it works, however, I dont get to pass the variables. How do I make this work?
Last edited by goku87 on 30. May 2010 20:15, edited 1 time in total.
goku87
 
Posts: 2
Joined: 29. May 2010 06:34

Re: <?php include("page.php?var=something");?> gives error

Postby Altrea » 30. May 2010 11:29

goku87 wrote:Using the include fuction while trying to pass a variable at the same time like this:

Code: Select all
<?php include("button.php?text=home&url=index");?>


Gives me this error code:

Warning: include(button.php?text=home&url=index) [function.include]: failed to open stream: No error in X:\Dir\WebSite\index.php on line 73
Warning: include() [function.include]: Failed opening 'button.php?text=home&url=index' for inclusion (include_path='.;X:\Dir\_xampp\php\PEAR') in X:\Dir\WebSite\index.php on line 73


Google isn't really helping me out. Everything works separately, and even together, except for the include statement. If i remove the ?text... at the end then it works, however, I dont get to pass the variables. How do I make this work?


include() expected a path given, no URL. In Paths there is no possibility to define GET-variables.
But you simply can use all variables of the parent-file
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8299
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: <?php include("page.php?var=something");?> gives error

Postby Nobbie » 30. May 2010 11:54

goku87 wrote:Using the include fuction while trying to pass a variable at the same time like this:

Code: Select all
<?php include("button.php?text=home&url=index");?>



You cannot pass variables via included Pathname. Simply do it that way:

Code: Select all
<?php

$text = 'home';
$url = 'index';
include("button.php");

?>


You can refere to $text und $url in button.php directly.
Nobbie
 
Posts: 8779
Joined: 09. March 2008 13:04

Re: <?php include("page.php?var=something");?> gives error

Postby goku87 » 30. May 2010 20:12

I got it working. I took all my "generating stuff" code, turned them into functions, and put it all in one file "generators.php" and put an include statement in the <head> for the generators.php.
Simple solution. I just needed a nap lol.

Code: Select all
<html>
<head>
   <?php
      include("generators.php");
      // includes button function
   ?>
</head>


So then I am able to call the button function whenever with the vars I want by using this in the html:

Code: Select all
<body>
   <?php echo button("Home","index");?>
</body>
goku87
 
Posts: 2
Joined: 29. May 2010 06:34


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 65 guests