Jump to content
xisto Community
Sign in to follow this  
sxyloverboy

Include Funtion Php Problems in xammp and php 5.1.1

Recommended Posts

Hi,

I just recently installed the latest versin of XAMMP on my computer which comes with php5.1.1 and i have been noticing some problems with the include(); funtion. This is a code that worked fine on Xisto hosting so I am thinking it has something to do with the php version of 5.1.1 since Xisto uses 4.3.X.

 

Now what the actual problem is is using the variables in the include function. If i have a normal include sentence like this one:

include "hello.php";
then it works fine but as soon as i start using variables it somehow dosent work at all.

 

I have already tried a variety of diffrent ways to write the include sentence but they all dont work !!

include("$id.php");include "$id.php";include "$id" . ".php";include ("$id" . ".php");

But they all dont seem to work. The error message im getting is this one:

Warning: include(.php) [function.include]: failed to open stream: No such file or directory in C:\Apache\xampp\htdocs\lasttry\index.php on line 117

 

Warning: include() [function.include]: Failed opening '.php' for inclusion (include_path='.;C:\Apache\xampp\php\pear\') in C:\Apache\xampp\htdocs\lasttry\index.php on line 117


So it looks like php is completely ignoreing the part with the variable because it tries to load only a stupid file called .php

 

I set the variable in my url like this ...index.php?id=home

 

 

Maybe someone can help me?

Share this post


Link to post
Share on other sites

I had almost the same problem. I solved it like this:

$id = $_POST['id'];include("$id.php");


That worked for me. It was weird because on my previous host it worked without the first line but on my localhosts with a PHP interpreter running it didnt, so I tried that and it worked. You could also try something like

$id = $id + ".php";include($id);


but im not sure about that. Your PHP script is basically saying that $id is empty so by doing the first thing (using $_POST['id']; ) it should work fine :lol:

EDIT: I'm using XAMPP too so maybe its the PHP version or just the interpreter
Edited by shadowx (see edit history)

Share this post


Link to post
Share on other sites

Here is a version of a script which I use to set the include from a query string. Notice that I check to see if the file exists and it also checks an array of acceptable values otherwise the include is set to index.txt as a default.

$submit = $_GET

;if( !isset($_GET

)   ) {				if (file_exists($data_array[0] . '.txt' )) {				include ( $data_array[0] . '.txt' );				}				else {					include ('index.txt');				}		}		elseif (in_array($submit , $data_array)) {				if (file_exists($submit . '.txt' )) {				include ( $submit . '.txt' );				}				else {					include ('index.txt');				}		}		else {				if (file_exists($data_array[0] . '.txt' )) {				include ( $data_array[0] . '.txt' );				}				else {					include ('index.txt');				}		}?>

Share this post


Link to post
Share on other sites

hehe cool thanks guys. that really helped. I think that the new version dosent make the _GET variables into normal variables and that the older version does. or maybe theres an option for that i dont know. but there is a technical term for it too. I know my files are going to exist because this is for a menu and it would be stupid if i had a menu but no sites to go with it :lol:. thanks guys :lol:EDIT: ...IF there is an option for pho to automaticly make the get variables normal variables. does anybody know where i can set it?

Edited by sxyloverboy (see edit history)

Share this post


Link to post
Share on other sites

IF there is an option for pho to automaticly make the get variables normal variables. does anybody know where i can set it?

I think you are talking about auto globals. If you are, in your php.ini file (I'm not sure where it would be for you), there should be something like:

register_globals = Off

If so, just change Off to On, and things like $_POST['test'], $_GET['test'], etc. would be $test.Once you've changed it, you'll have to restart the server. I've forgotten how XAMPP is set up, so that's all that I can tell you.

Share this post


Link to post
Share on other sites

If so, just change Off to On, and things like $_POST['test'], $_GET['test'], etc. would be $test.

I'd only do that if you know you're going to be able to do the same on your live site. No point doing something on your local machine only to find the server you've chosen to host your site won't let you do the same.

Share this post


Link to post
Share on other sites

If the script is going to be used with Xisto, then it wouldn't hurt turning on auto globals on the local machine. Xisto has auto globals (and a few other things I believe) turned on.

Share this post


Link to post
Share on other sites

But Tyssen's point is work considering. If you can do something without using the Global variables, your site will be more secure. They are set to be off for a reason on most Hosts.

Share this post


Link to post
Share on other sites

hi , i think $id.php is not correct

$id is variable and if you user variable in "" its not work true

some programs like XAMPP and wamp and ... dose not support some code

i think best why to test your code is uploading your file on your server and test it

you must do some config like register_globals to this programmas do your code

some functions Just working with Register Globals and some is not

if register_globals = Off your codes donest work correct

sorry my englsish is not very good , :lol:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.