Reputation: 327
Bit of a problem here, I have a file with the following code:
<?php
$kvkvariable = 000050650459;
include("../../../../../../httpdocs/profiel/indextemplate.php");
?>
Inside the included PHP file, I need $kvkvariable
. However, when I echo this variable it's not showing the number I want it to show?
If I place the defining code of the $kvkvariable
inside indextemplate.php
it works fine. I thought including was the same as pasting the code in the same file? How do I fix this?
Thanks!
EDIT:
indextemplate.php immediatly starts with this:
<?php
echo "Dit is kvk: ".$kvkvariable."";
It gives the following result:
Dit is kvk: 1337893
To be honest with you, I have no idea where he gets that number!?
Upvotes: 0
Views: 1236
Reputation: 1923
how about:
<?php
$kvkvariable = 000050650459;
include( "../../../../../../httpdocs/profiel/indextemplate.php?myvar=" . $kvkvariable );
?>
And you treat the variable inside your include as $_GET[ 'myvar' ]
Then your second file should be like this:
<?php
echo "Dit is kvk: " . $_GET[ 'myvar' ] . "";
Upvotes: 1
Reputation: 327
The answer to my own question was fairly simple, use "" around the number defining the variable! My bad.. Maybe this helps someone out!
Upvotes: 0
Reputation: 10732
<?php
$kvkvariable = 000050650459;
include("../../../../../../httpdocs/profiel/indextemplate.php");
?>
When PHP sees a number beginning with a 0, it assumes it's octal - and if you run 000050650459 through an octal to decimal converter, it gives you 1337893.
So your include is working as expecting; it's PHP's variable typing that's not doing what you expect.
Upvotes: 2
Reputation: 1889
Try using php's global
keyword.
<?php
global $kvkvariable;
$kvkvariable = 000050650459;
include("../../../../../../httpdocs/profiel/indextemplate.php");
?>
Upvotes: 0