10

i need to call a php inside another php file and pass some arguments also. how can i do this?? i tried

include("http://.../myfile.php?file=$name");
  • but gives access denied. i read like v must not set allow_url_open to OFF.

if i write like

$cmd = "/.../myfile.php?file=".$name";
$out =exec($cmd. " 2>&1");
echo $out;
  • gives error as /.../myfiles.php?file=hello: no such file or directory.

how can i solve this???

4
  • 2
    What exactly do you need to do. Fetch a block of PHP for execution inside the current script, or run an external script with no connection to the current script? Commented Mar 22, 2011 at 10:10
  • use curl and make allow_url_open ON Commented Mar 22, 2011 at 10:10
  • does this php file located on the same server? Commented Mar 22, 2011 at 10:17
  • i got the answer.... stackoverflow.com/questions/2644199/… Commented Mar 22, 2011 at 10:18

4 Answers 4

20

You don't have to pass anything in to your included files, your variables from the calling document will be available by default;

File1.php

<?php

$variable = "Woot!";
include "File2.php"; //if in the same folder

File2.php

<?php
echo $variable;
Sign up to request clarification or add additional context in comments.

3 Comments

That's right, basically php just appends the documents so any variable declared before will be also available
this syntex to include file worked for me not above. include("insert_DB.php");
It should be include "File2.php";
1

the location in your code is incorrect:

$cmd = "/.../myfile.php?file=".$name;

Comments

0

you can include file over http only if the allow_url_fopen is set to TRUE, and the same parameter allow you to pass variables to the files...

Comments

0

You should not include files via HTTP connection - that's almost always a serious security problem.

If you must do this, you have to set allow_url_include and allow_url_fopen to ON but neither is a recommended procedure.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.