What is the actual meaning of "script" in php? [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I know that php is a scripting language. But some of php codes/docs, like when i tried to use magic methods, still use the "script" word. Like the __invoke() method that is called when "a script tries to call an object as a function". Here, in "script tries" - what exactly does "script" here refer to?

A script is a pretty vague term, generally, a script is a group of code that preforms in and around a root goal, like a script to generate a json file that has some input parameters which slightly modify the final output.
In PHP, you might have one main script in your project, or you may have many fragments - there is not hard line that says what is a script.
You may even call other scripts from yours; voting to close as opinion based.

Related

Why PHP built-in standard functions have empty body? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
How is this possible to have an empty body for a function ?
Is this related to C/C++ (that PHP is written with ) ?
Or is it related to CGI mechanism or something like that ?
I want to know how functions work under the hood.
What if I want to add a simple function that returns "Hello world" written in C++ to PHP ?
Thanks in advance.
These are just dummy files (implemented by the IDE) that serve documentation & autocomplete purposes for the builtin functions / classes.
If you want to see how PHP works under the hood, take a look at its source code: https://github.com/php/php-src.
If you want to extend PHP with custom functions, you can write an extension in C++. There are a lot of tutorials on how to get started.

Is it possible in PHP to exit an included file through something like die()? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
My main PHP file includes several PHP files. At the beginning of one of them I'm testing a variable. If it passes the test then I want the whole script to run, otherwise I want to exit. Is it possible or do I have to condition my entire script (and not use anything similar to die())?
Well, normally it is bad practice to just die() anywhere in a script. However if you have a background script for example and you just want to quit, you can use die() everywhere. A better approach is for example to throw an exception and catch it on a top level

How to Run PHP coding dynamically [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to type php coding in textarea, then after submit it should run the php coding and produce result. Is this possible ?
To upload changes in live, I need to get two level approve, If any errors occur i could't fix it quickly, If above thing is possible I can enable error log, dynamically print array and so on...
Yes, you can POST value of textarea and then evaluate its content as PHP code using eval function, but make sure you restrict access to this feature, because it's very dangerous if you allow random people to use it. You can even simulate something like online php compiler using AJAX calls.

Need a safe way to execute external code [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I was wondering if it was possible to allow people to write and execute PHP code from my website without the use of "eval" due to risks.
I have googled around and I did find some answers, just not the answers I was looking for (call_user_func).
This is not what I am looking for as it does not allow people to run a full PHP script.
It's a small group of people executing it so server load will not be an issue.
edit 1: Users should not be able to corrup/delete files;
Users should be able to create complete scripts.;
Users should be able to run html code but trigger php as soon as php tags are used.
You can write your own wrapper process around php that uses ptrace to control the execution of the child php process to prevent it from opening file handles, connecting to the network, etc.
That way, even if people decide to try using malicious code in eval, the system calls will be blocked on the native level.

separating header and footers into their own files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Question: I've read a lot of tutorials/books that have taught putting the header and footers into their own files and using php to include them in the content pages.
However, if you have javascript running in those headers or footers- isn't this "bad" design- or does it not really matter?
I guess I take out the javascript if it's not needed for a page and I don't really mind CTRL+C. However I can see the usefulness and efficiency of making a change in only one file instead of all of them.
You should start using some template engine instead. Something to start with: Twig and Smarty
The most important feature you will like is called Template Inheritance
I would always separate your header and footer files out, it is a nightmare otherwise!
Just load in the JS when you need it, if using PHP just check the $_SERVER vars - http://uk.php.net/manual/en/reserved.variables.server.php

Categories