Sending Arguments To Inside Another Php Code

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
Mustafa
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Mar 25, 2017 10:51 am

Sun Mar 26, 2017 11:33 am

Hello guys ;

I want to send for example some argument value from xxx.php to yyy.php ,
but the yyy.php is in the different directory like /home/root/

Is there any solution to send the argument ,which is defined in xxx.php , to yyy.php
and assign the Posted variable to another variable in that way I will use these posted variables in different directory to ?

Thanks....

Best Regards
Mustafa

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 747
Joined: Mon Feb 22, 2016 5:52 pm

Sun Mar 26, 2017 2:42 pm

The answer is probably yes, just use one of the includes or requires.

You'll need to be a bit more specific though; variables declared in normal flow are global, even between included files, there's no need to "post" from one file to the other.

If your directory structure is

Code: Select all

root
	x_dir
	y_dir
And your xxx.php is in x_dir and is the file which is called:

Code: Select all

<?php
/* xxx.php
	full address: /x_dir/xxx.php
	The file which is called by the browser
*/

$root = $_SERVER['DOCUMENT_ROOT'];# This is the web site root, i.e. where the browser goes
$funny_var = 'A joke';

include $root.'/y_dir/yyy.php';
?>

Code: Select all

<?php
/* yyy.php
	full address: /y_dir/xxx.php
	The file included from xxx.php
*/

echo $funny_var;#funny_var is available inside this file, and so is $root
$funny_var = "I'm not laughing";
echo '<br>', $funny_var;
?>
Just be careful that you don't overwrite the variables with something you don't want.

Mustafa
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Mar 25, 2017 10:51 am

Mon Mar 27, 2017 9:12 am

Hello hyper;

I missed some point about argument , these argument values are changing in my project we are controlling camera from webserver , and index.html post these variables to the cam.php which is in the /usr/share/apache2/ htdocs , when button is pressed like zoom button , cam.php takes the zoom value which is between 0-100 , and it need to send to the /home/root/cam1.php ... , Depending on these zoom argument values cam1.php will send some data to serial port . Is it possible to send these changing values to the cam1.php from cam.php ?

And today we make some changes in our html code , We change the posted zoom value path to the /home/root/cam1.php
when we change the directory of the Post process , it sees the path like /usr/share/apache2/htdocs//home/root.

Do you have any suggestion ?

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 747
Joined: Mon Feb 22, 2016 5:52 pm

Mon Mar 27, 2017 1:33 pm

If you are controlling a camera, use one form and one script to process the data; I don't understand why you want to use another file? if your xxx.php and yyy.php are to control the x & y positions, there's no need as it adds unnecessary complication - if your form moves or states an absolute position, then process the form accordingly.

$_POST data is global and therefore available in any script included from the form as per my last post.

Mustafa
New php-forum User
New php-forum User
Posts: 5
Joined: Sat Mar 25, 2017 10:51 am

Tue Mar 28, 2017 6:38 am

hyper wrote:
Mon Mar 27, 2017 1:33 pm
If you are controlling a camera, use one form and one script to process the data; I don't understand why you want to use another file? if your xxx.php and yyy.php are to control the x & y positions, there's no need as it adds unnecessary complication - if your form moves or states an absolute position, then process the form accordingly.

$_POST data is global and therefore available in any script included from the form as per my last post.
I couldnt give the root permission from another path to send data from serial , then I write to the /HOME/root /myphpcode.php to post the data to the serial port . thats the reason . :)

Post Reply