Jump to content

Recommended Posts

Hi,

 

I have a secript that is graping data from data base ..

 

my folders are like this

 

docs

--includes

.

....etc

 

in the docs folder there is a file called channels.php and it have this code

 

<?php
$id = trim($HTTP_GET_VARS[id]);
include('includes/funcetion_channels.php?channel=$id');
?>

 

in the includes folder there is a funcetion_channels.php with this code inside

 

<?php
include("config.php");
$channel = trim($HTTP_GET_VARS[id]);
if ($channel == "main")
{ Case 1 Actions
}
else
{ Case 2 Actions
}
?>

 

 

now when i call the funcetion.php it gives me this error

 

Warning: Failed opening 'includes/funcetion_channels.php?channel=$id' for inclusion (include_path='.;c:\php4\pear') in c:\phpdev5\www\alaineye\channel.php on line 3

 

while when i run the funcetion_channels.php file sending the channel paramter in the url i can get data, which means it works very fine ...

 

how can i include the funcetion_channels.php inside the channels.php file while to get the data of a specified channel using the funcetions inside the funcetion_channels.php file ...

 

notice that i call the channels.php file using this url

 

channels.php?id=1

 

 

 

Thanks

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/62861-solved-probleme-with-include/
Share on other sites

my friend was having this problem

You can use $_GET in an include function (.php?something=123)

Youll need to include the file then on that file have a function in witch you can pass the variable to.

 

sir,

i cant include the file without setting the channel variable, because it will do Case 1 Actions which will not get the data i want, it will run another query

 

Variables only work if you place them inside double quotes. If you place a variable within a single quote PHP will treat it as text. In your case PHP is doing just that. It is trying to include a file called funcetion_channels.php?channel=$id within includes/

 

Also as a side note you can only use url parameters within an include if php has url_fopen (or url_include if your site runs on PHP5.2.x) enabled within the php.ini.

Variables only work if you place them inside double quotes. If you place a variable within a single quote PHP will treat it as text. In your case PHP is doing just that. It is trying to include a file called funcetion_channels.php?channel=$id within includes/

 

Also as a side note you can only use url parameters within an include if php has url_fopen (or url_include if your site runs on PHP5.2.x) enabled within the php.ini.

Variables only work if you place them inside double quotes. If you place a variable within a single quote PHP will treat it as text. In your case PHP is doing just that. It is trying to include a file called funcetion_channels.php?channel=$id within includes/

 

Also as a side note you can only use url parameters within an include if php has url_fopen (or url_include if your site runs on PHP5.2.x) enabled within the php.ini.

 

ok i changed the code to be

 

include("includes/funcetion_channels.php?channel=$id");

and i got the same error, more over am working on php 4.2.2

Are you sure its the same exact error? the id variable should now be being parsed resulting in php including a file called

funcetion_channels.php?channel=value_of_id_var_here

 

eg if $id was set to the number 2 it'll be

funcetion_channels.php?channel=2

Are you sure its the same exact error? the id variable should now be being parsed resulting in php including a file called

funcetion_channels.php?channel=value_of_id_var_here

 

eg if $id was set to the number 2 it'll be

funcetion_channels.php?channel=2

 

this is the message

 

Warning: Failed opening 'includes/funcetion_channels.php?channel=1' for inclusion (include_path='.;c:\php4\pear') in c:\phpdev5\www\alaineye\channel.php on line 3

Yep its parsing your variable but it cant find the file funcetion_channels.php is that file name spelt correctly? To me it looks like it is supposed to be function_channels.php

 

thanks , i have changed the file name, and used the same name in the code, but stell getting the error

 

<?php
$id = trim($HTTP_GET_VARS[id]);
include("includes/function_channels.php?channel=$id");
?>

 

 

 

[attachment deleted by admin]

Can you run a php script with just phpinfo() in it for me and then scroll down and look for the following lines:

url_fopen

url_include (if it exists)

 

What are their values?

 

I cant find it there, I only founded

allow_url_fopen / Local Value 1 / Master Value 1

What happens if you use a web address in the include

$id = trim($_GET['id']);
include("http://mysite.com/includes/function_channels.php?channel=$id");

Change http://mysite.com/ to your websites address.

 

I think you can only use url parameters if you are using a url path rather than a filesystem path.

What happens if you use a web address in the include

$id = trim($_GET['id']);
include("http://mysite.com/includes/function_channels.php?channel=$id");

Change http://mysite.com/ to your websites address.

 

I think you can only use url parameters if you are using a url path rather than a filesystem path.

 

ok, i tried something elese

i moved the function_channels.php to the same directory of channel.php , and i got the same error

 

 

i fixed it another way

 

 

1st in the function_channels.php 

 

i changed

include("config.php");
$channel = trim($HTTP_GET_VARS[channel]);
if ($channel == "main")

 

to be

 

include("config.php");
if ($channel == "main")

 

than , in channels.php i changed the code to be

 

$channel = trim($HTTP_GET_VARS[id]);
include("includes/function_channels.php");

 

so in this case , i defined the channel vriable, and after that i included the function_channels.php , and while the $channel is predefined it will not ask for it again it will contenue to work and run the SQL command using the defined value

 

thanks for assistance

 

Might seem like a strange question but...why take such an approach to including a file to your script? Even if the function you're including is dependent on the value you're trying to pass to it here...there are easier and less problematic approaches.

 

 

Sir,

You are totaly right, but I am using some functions many times in the project, and including or calling the functions will make it easier for me to fix bugs, more over regarding that value that i pass it will be used in many other files, because once you call the channel.php file, it will call

 

functions_channel.php

functions_news.php

functions_calendar.php

functions_adserv.php

 

which will make some queries accourding to the $channel value.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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