Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm filling out a job application which has asked me to write a function which you submit to them as a .php file. The last line of the specification says:
Make sure your file can be executed from the command line: php meats.php (this helps us to check if the code works before even looking at it)
Does anyone know what that means? I've checked that function works fine on my hosting environment but I'm just not sure there is something else I need to do??
Thank you
Without seeing your code, you'll need to make sure it's not using anything that's dependent on being run rendered in the browser executed on the server via a client browser's HTTP request to a webserver, which may send data back to the browser for rendering. These include $_GET,$_SERVER['DOCUMENT_ROOT'] (for relative web paths), and other such variables. You may need to convert these to use magic constants or otherwise work around your limitations.
I'm about to send you down a rabbit hole if you've never been to your command line, but you should SSH into your web server and try to execute your php file just like they said. You'll navigate to the directory with the file and run
php meats.php
Then, the command line will spit out any echos that you've got, or do whatever else your code does.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Hello I'm new to both PHP and python but I'm using them both in my graduation project I have an OTP code to generate a random number and send SMS to phone numbers and another code that runs a fingerprint scanner.both are working fine when I use exec() in PHP to run them in cmd but when using browser only the otp code works with the webpage, I've changed the permission of the apache user and gave it root privileges and tried both system() and exec() functions but still nothing shows up when using trying to execute the fingerprint code from browser
I would appreciate any help because I am stuck on this for many hours days now
I've changed the permission of the apache user and gave it root privileges
OMG no.
If your supervisor (whom is being paid to give you advice) thinks this a good idea, then find another supervisor.
You have not provided nearly enough information to form an opinion on the cause. You need to investigate which file permissions are relevant to the problem - that is Unix filesystem privileges on executables, devices and data files, but you also need to look at any mandatory access control systems which might be in play (SELinux, Apparmor, smack). You should also try running the programs from an interactive shell as the Apache uid. Note that it is usually a good idea to severely restricted the programs the webserver can run and whitelist specific actions for the webserver/webserver uid via sudo.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Issue: I made an application without problems working on localhost where I debuged it. But when I uploaded it on server in internet (my school server) few SQL didnt work, there were no PHP error messages and i tested SQL code in phpMyAdmin(on server) and there it worked.
Guys,can you help me solve this please?
The main problem is that you cannot provide any useful information about whats wrong. In this case, we need to tell PHP that for any and every problem please send it down to the client on page load. Normally in production this is precisely what you do not want to do but in this case- we need it.
Put the code below at the beginning of your index.php file, or whatever file your web server is configured to send requests to:
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(E_ALL);
So long as your web server is successfully sending requests there, something should come up on page load that will help us determine the issue.
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'm arriving in PHP world just now.
By the experiments I'm doing, I'm making some assumptions:
1- A PHP script is launched when the file it resides on is requested via http.
2- The script creates an independent scope for it's vars.
3- The script can only access any other DOM element at the end of it's execution. However, it can perform file's jobs any time.
Are those rights assumptions?
What other actions it can do while being executed?
Thanks.
All of these assumptions are at least partially incorrect or, in the case of the last one, a bit nonsensical. You might want to find a good tutorial and also read through PHP The Right Way.
To address your assumptions in part:
1- A PHP script is launched when the file it resides on is requested via http.
Usually, but not necessarily. PHP files can also be run from the command line or via other protocols.
2- The script creates an independent scope for it's vars.
No. Any variables created outside of a function, class, or method have global scope and are automatically shared across any included or required files.
3- The script can only access any other DOM element at the end of it's execution. However, it can perform file's jobs any time.
This doesn't really make sense; PHP scripts don't have anything to with accessing the DOM. PHP runs purely on the server side. It can do anything on the server (assuming correct permissions, etc.) right up until it terminates.
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 8 years ago.
Improve this question
I've got a problem. After moving a project to another server I get strange string "192" which is inserted before every response from server. I did no changes into source code and it works fine on another server. I've only copied project... Really. That's all.
This is how it looks:
It can be beared when dealing with generated pages. but json reponse is not correct so it gets broken because of this number "192".
In the root folder /var/www/html I have only this project. Nothing else.
I guess it must be something with php settings. Thanks in advance!
The problem is with the code off course. Check the configuration files you are adding before executing any file of the view.
If you want to verify there is something wrong with the code, you may just put an empty hello world file and execute it from the browser. See if 192 comes there also or not.
Something like this on /var/www/html/test.php
<?php echo "Hello World"; ?>
Now run your website http://yourwebsite.com/test.php and share the output.
If the 192 is not in your code (and since it doesn't show on a different server, it certainly seems so), another very strong contender from where it is coming from is the php.ini option, auto_prepend_file.
auto_prepend_file string
Specifies the name of a file that is automatically parsed before the
main file. The file is included as if it was called with the require
function, so include_path is used.
The easiest way to find out if there is a file being included before all of your requested pages is by searching the phpinfo() output for auto_prepend_file, and editing the php.ini file to remove it if it is there.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Can PHP pages be run locally?
I am trying several demos on creating a contact form, at the moment I am trying this one:
http://www.html-form-guide.com/contact-form/php-email-contact-form.html
I have downloaded the source files and put my own email address in, but when I click submit I get directed to the PHP page. The form's action attribute is set to that PHP page, so I was wondering if it is because PHP is not able to run locally? If I want the form to submit and send to my email would I need to put the downloaded source pages online to make them work?
This is not the only tutorial I've used where this happens.
Sorry if this is a silly question - newbie web developer :).
Thanks.
PHP, in this context, is a server side language. It must be run by a webserver.
The webserver can be installed and run locally.
PHP needs to be executed server-side, which means you will need to set up a local webserver.
The best way to go would be taking a look at WAMP or MAMP or LAMP, depending on your operating system.
You need to be running a PHP server locally, and have the file "hosted" by the server (in the same folder, but usually /var/www/). There are a verity of free programs for this. I like WAMP ( http://sourceforge.net/projects/wampserver/)
You should simple install WAMP server. If you use Windows I recommend this one: http://www.easyphp.org/
When you install it you should copy php file to projects directory and then you can run in your browser http://localhost/projects/ to see your file and to execute it