Why might this work on my server but not my schools? - php

I created a captcha just now, and it works PERFECTLY on my own server. On the school's server, it doesn't generate an image. Why might this be? The difference in code is one line.
Edit: Originally, it was working, but I deleted the directory by mistake and I do not know why did it suddenly work in the first place.
Update: I var_dumped() everything and everything is being set correctly.
Source code on school server:
Update: I figured it out! I'll post the answer later.

Make sure that GD library is enabled in your school's server.
Also try putting these lines on top of your script to see if there are any errors:
ini_set('display_errors', true);
error_reporting(E_ALL);

It is just useless to direct such kind of questions to SO.
There must be thousands of reasons.
And, of course, without access to your server and environment, nobody can say, just by looking into working code.
The only person who can answer this question is you yourself.
With help of your server, of course.
You must ask your server for errors.
ini_set('display_errors',1);
error_reporting(E_ALL);
but sometimes (in case of parse errors for example) this won't work. In this case you have to either set these params via .htaccess or check web-server's error log.
Also, you have to do something.
At least add some text output in the script to be sure it being executed.
print out variables using var_dump() to ensure thy contain right values.
Add an intentional error to ensure you CAN see them if any.
Do something, don't sit watching code!
Some more info on how to help yourself: http://www.ibm.com/developerworks/library/os-debug/

Related

Notice warning from PHP in Symfony uploading file

I have a form that allows upload three files at the same time but just one is required. That works fine, my only problem is the following: if I upload three files I haven't any problem but if I upload one or two files (leaving two or one files empties) I obtain the following notice:
Notice: No file uploaded in Unknown on line 0
As much as empty files. The files are uploaded properly without any other problem, but I want remove that notice... or unless hide it, although I prefer remove it. I tried to hide it using
error_reporting(0);
and
ini_set('display_errors',0);
but neither of two worked...
It is the first time that I have problem, if someone could lead me I'd be very grateful due to that I am stuck with it.
If you are having the same problem as me, check with phpinfo() if you are using a debug version of PHP. If you see that Debug Build has a value of yes, your problem will be fixed if you install a live version of PHP instead of a debug version
The Error itself is caused by running a Debug version of PHP 7, see the bug report. As noted by HPierce because it was a Debug build it overrides the usual PHP settings for error_reporting. However as the Original question is actually about how to hide certain [expected] error messages (Notices), my answer is to this detail specifically.
Kevin, the attempted ways to hide errors you've listed in your question would normally work on non-debug PHP builds. However, it is unwise to ignore the errors, rather than solving them at source. It's also (more) unwise to hide all errors simply due to having expected errors appearing.
As it's only a Notice, you can work around it by setting your error_reporting() value as below:
//report all errors except notices.
error_reporting(E_ALL & ~E_NOTICE);
I would suggest this is far wiser than turning off error reporting entirely which is not recommended. If you want to stop errors being output to browser (as referenced by Tina) you can use display_errors.
Perhaps you may also need to set
ini_set('error_reporting', 0);
depending on your php ini configuration?
Also make sure you set it before carrying out any of the code.

How do I get my programme to work with the function ob_start();?

I am student (not long being doing PHP so don't know a lot about PHP) but I am trying to get my code to work, at first it was working fine, until it was transfer to a different server but since it had I was getting the following error:
'Warning: Cannot modify header information - headers already sent by (output started at /home/deanj/public_html/login.php:21) in /home/deanj/public_html/login.php on line 60'.
Then I got suggested to use ob_start(); so I tried to use it but didnt get much good results. So what do I need to do use this? and is it the best option? if not what is?
p.s. please make it as simple as you can.
In php.ini set output buffering to On. You should NOT have to modify your code using ob_start() since it is clearly an environment issue. The key to knowing that is in your question, "it was working fine, until it was transfer to a different server".
To fix it, in your php.ini file you want:
output_buffering = On
http://php.net/manual/en/outcontrol.configuration.php
That is also likely why the same code worked on one server, but not on your new one (since output buffering was configured differently).

php login script error

I have this login script working just fine on one server but not on other and coudn't figure out why.
include_once 'include/processes.php';
$Login_Process = new Login_Process;
$Login_Process->check_status($_SERVER['SCRIPT_NAME']);
and the third line won't display the server status, the code display on my web page, and didn't go to main page. any idea may cause the issue.
thanks.
The third line isn't working, most likely, because you have a Fatal Error being generated somewhere as a result of this line:
$Login_Process = new Login_Process;
Either use ini_set to change the errors being displayed, or set up an error log. You basically need to know what the errors are, and then you can deal with them.
It could be many things, some of which may be the configuration.
The first thing I would check is the PHP version. Make sure that nothing in your scripts or your php.ini file conflict with the version of PHP you're migrating to.
After that, go through the functions you're calling and make sure nothing is deprecated in PHP on the second server.

Specific php question

I am fairly new to creating websites and I have done a website that I did in a sandbox server on my personal computer, it works brilliantly, but as soon as I try to put it on my companies server to go up on the internet it doesn't work anymore. What the site does is it takes fields from an html form and then does a sql search of a database that I set up and works fine. Then after the user is done with the form they hit submit and the sql is run and results are returned to the same page. The form action="" and then the results are returned. I am not sure if the companies server has php installed, but I don't know if that would be a problem or not because the browser should still be able to display the php code. I have no problems with the html form, it is just when I hit submit that the page is returned and nothing is displayed.
Any help is welcome.
"I am not sure if the companies server has php installed, but I don't know if that would be a problem"
It is. Browsers can do nothing with PHP. Maybe you shoud register for a free hosting provider and learn the basics of hosting there.
PHP is a server-side language (i.e., it runs on the server, not the user's machine). Therefore, it must be installed on the company's server for any PHP code to execute properly. Browsers cannot interpret PHP code, and moreover PHP code is executed before the browser even receives any information (PHP: Hypertext Pre-Processor). Check that the server has PHP installed before you continue. (Also be aware of versions and features. For example, to use many new PHP features your server must be running PHP5.)
If you find that PHP is installed: Check your PHP syntax; make sure that no headers are sent after text is sent to the page; and make sure that there are no loops or anything in your code that could cause the script to continuously run without printing to the page.
Also, since your page is returned when you hit 'Submit,' but no new information is shown, make sure that there is not a problem with the MySQL configuration (e.g., incorrect password, query syntax, etc).
First you have to be sure that server has PHP installed.
make a file named phpinfo.php with this line
<?php phpinfo() ?>
and call it.
If it won't print out PHP config, you have to install PHP first.
Otherwise the problem most likely in the form of PHP tags, and you are using <? instead of <?php.
To solve, you can either change tags or set short_open_tag to on in the php.ini
According to your comment
when I hit submit that the page is returned and nothing is displayed
I am going to make an assumption that you are getting a blank page. If that is correct, then I am also going to follow that up with the assumption that PHP is installed, there is an error in your script (my guess is the database connection), and that the error is not being displayed.
Add these lines to the top of your page and post back with the result:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Ya I think there is a problem in your database connection.First run your connect file whether it is showing some error or not.Plase add this line to your page:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
And please modify your php.ini file with this line:
display_errors = on

Multiple mysqli connection problems

I am having some strange issues with mysqli connections.
I was working on a page with mysqli, and it has been working fine all day. I then made a copy of this page, and stripped it down to debug a problem, and tested it as a different file. It worked fine connection wise. Upon trying to request the original file I was working on, I get the error:
Access denied for user 'user'#'localhost' (using password: YES)
I don't understand why. I have closed the connections after I have finished using them each time, although I don't see why that would be an issue. Interestingly, an older version of the file works fine, despite containing the exact same connection details and code.
What is going on?
Turn the question around. Rather than saying the two versions (the one that works and the one that doesn't) are identical in the aspects that matter, focus on the ways in which they are different and try to isolate which difference(s) also matter.
Make an additional copy of the working version. Verify that it works. Try making it into a copy of the non-working version by applying as many of the changes as you can, one by one, to this test copy, until you have something that is as close as possible to the broken version but that still works. Compare these two, and that should show you where the problem is.
Weird. If you are testing files from the same machine they should be working (if they have same code).
Check again username & password, i.e. spaces or strange chars.
Just for the sake of it, run a diff between the working copy and older version of the file. Check for any issues like: moved brackets, variable name changes, etc. Maybe the part of the code that defines the username and password never gets run!
If you need a free program for that, check WinDiff
If you put:
error_reporting(E_ALL);
as the first line in your code do you get any errors on either page? There may be something strange like the program can't open an include file anymore.
You said copying File A to File B means File A doesn't work. What happens if you copy File A to File B, delete File A then copy File B to File A?
Ensure that your IP is added to the MySQL allowed connections list, also ensure your password is correct. Try providing a full hostname rather than localhost if possible.
Post your code if un-successful.

Categories