I want to transfer the value of the $ x variable from the getdata.php file to the html tag of the data.php file

In this case, the file getdata.php is located in the php directory, and the data.php file is in the server root.


I tried to do this:

File code getdata.php

<?php $x = 'ΠŸΡ€ΠΈΠ²Π΅Ρ‚ ΠΌΠΈΡ€!'; require_once('../data.php'); ?> 

The code of the data.php file

 <html> <head> </head> <body> <div>ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Π°Ρ ΠΈΠ· php: <span><?php echo $x; ?></span> </div> </body> </html> 

Nothing is displayed.


I tried to do this:

File code getdata.php

 <?php $x = 'ΠŸΡ€ΠΈΠ²Π΅Ρ‚ ΠΌΠΈΡ€!'; ?> 

The code of the data.php file

 <? include_once "php/getdata.php"; ?> <html> <head> </head> <body> <div>ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Π°Ρ ΠΈΠ· php: <span><?php echo $x; ?></span> </div> </body> </html> 

Nothing is output and the following occurs: Warning: include_once (php / getdata.php): Wow: \ domains \ test \ data.php on line 1

Warning: include_once (): Failed opening 'php / getdata.php' for inclusion (include_path = '; w: / modules/php/PHP-7.2-x64; w: /modules/php/PHP-7.2-x64/PEAR / pear ') in W: \ domains \ test \ data.php on line 1


Tell me please, what am I doing wrong?

  • include_once "/php/getdata.php"; for a start, the last .php superfluous, and the first slash is needed to access the file from the root of the "site", but here I can be misled, because I am not a theorist, I could forget everything for a long time - DaemonHK
  • All the same, the result is the same ( - Kirill Mironov
  • one
    include_once __DIR__ . "/php/getdata.php"; or chdir(__DIR__); include_once "php/getdata.php"; chdir(__DIR__); include_once "php/getdata.php"; - ArchDemon 2:49 pm

1 answer 1

getdata.php

 <?php $x = 'ΠŸΡ€ΠΈΠ²Π΅Ρ‚ ΠΌΠΈΡ€!'; ?> 

data.php

  <? require($_SERVER["DOCUMENT_ROOT"]."/php/getdata.php"); ?> <html> <head> </head> <body> <div>ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Π°Ρ ΠΈΠ· php: <span><?php echo $x; ?></span> </div> </body> </html> 

Error due to slash in address

  • All the same, the result is the same: Nothing is output and the following occurs: Warning: include_once (/php/getdata.php): failed to open stream: No such file or directory in W: \ domains \ test \ data.php on line 1 Warning: include_once (): Failed opening '/php/getdata.php' for inclusion (include_path = '; w: /modules/php/PHP-7.2-x64; w: /modules/php/PHP-7.2-x64/PEAR/pear ') in W: \ domains \ test \ data.php on line 1 - Kirill Mironov
  • @ Kirill Mironov error because the interpreter does not find the file getdata.php, the path is not correct, so try it, as I sent it in the answer. Everything will work - Dmitriy
  • If the file is in the root, then require_once ('./ data.php'); - insun