How can i run php file in php?

I want to call a PHP file that starts like

I call from the PHP like this:


I get:

line1-> cannot open ?: No such file
line 3 //Connection: not found
line 4 Syntax errror: "("

Why doesn't this correctly execute the name.php file?

How can i run php file in php?

asked May 15, 2010 at 17:41

It's trying to run it as a shell script, which interprets your token as bash, which is a syntax error. Just use include() or one of its friends:

For example, in a.php put:


In b.php put:


Prints:

eric@dev ~ $ php a.php
onetwothree

How can i run php file in php?

answered May 15, 2010 at 17:50

3

exec is shelling to the operating system, and unless the OS has some special way of knowing how to execute a file, then it's going to default to treating it as a shell script or similar. In this case, it has no idea how to run your php file. If this script absolutely has to be executed from a shell, then either execute php passing the filename as a parameter, e.g

exec ('/usr/local/bin/php -f /opt/lampp/htdocs/.../name.php)') ;

or use the punct at the top of your php script

#!/usr/local/bin/php

answered May 15, 2010 at 17:54

How can i run php file in php?

Mark BakerMark Baker

206k31 gold badges338 silver badges380 bronze badges

1

Sounds like you're trying to execute the PHP code directly in your shell. Your shell doesn't speak PHP, so it interprets your PHP code as though it's in your shell's native language, as though you had literally run at the command line.

Shell scripts usually start with a "shebang" line that tells the shell what program to use to interpret the file. Begin your file like this:

#!/usr/bin/env php

Besides that, the string you're passing to exec doesn't make any sense. It starts with a slash all by itself, it uses too many periods in the path, and it has a stray right parenthesis.

Copy the contents of the command string and paste them at your command line. If it doesn't run there, then exec probably won't be able to run it, either.

Another option is to change the command you execute. Instead of running the script directly, run php and pass your script as an argument. Then you shouldn't need the shebang line.

exec('php name.php');

answered May 15, 2010 at 17:50

Rob KennedyRob Kennedy

160k21 gold badges273 silver badges460 bronze badges

2

This came across while working on a project on linux platform.

exec('wget http://)

This runs as if you run the script from browser.

How can i run php file in php?

Dharman

27.7k21 gold badges75 silver badges126 bronze badges

answered Jan 7, 2014 at 6:18

AmarAmar

2,1011 gold badge12 silver badges16 bronze badges

2

How do I run a PHP file?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

How do I open a PHP file in PHP?

Go to the location of your PHP file, then click the PHP file to select it. Click Open. It's in the bottom-right corner of the window.

How do I call a PHP page from another PHP page?

Answer: Use the PHP header() Function You can simply use the PHP header() function to redirect a user to a different page. The PHP code in the following example will redirect the user from the page in which it is placed to the URL http://www.example.com/another-page.php . You can also specify relative URLs.

How do I run a PHP file on a website?

php" file extension. Open up any Web browser on your desktop and enter "localhost" into the address box. The browser will open a list of files stored under the "HTDocs" folder on your computer. Click on the link to a PHP file and open it to run a script.