I am checking if the cookie exists or not. Code run perfect on localhost but not working on server.
if(!isset($_COOKIE['checkuser']))
{
// Create a cookie
}
else
{
// do other other action
}
page is not being load on if accessing from webserver. but on localhost its work fine. is there is some setting that I need to do for this ?
If your error is "the page is not loading" then it is almost certainly not related to the code you posted. You mention in a comment that you're doing some database calls in code you didn't post - that's far more likely to cause trouble than an isset() call.
What error are you seeing? If you are seeing just a blank page, that's likely a syntax error which is being logged to the server's error log rather than to the screen, for security purposes. Check your server's error logs for an associated message.
It's likely your server is running either a different version of PHP or a different security level (PHP safe mode, for instance) which is causing it to fail on the server but not on your machine. Alternatively, it may be failing to connect to the server's database.
Please update your question with more information (more code and/or the exact error message would be a good start) if this isn't enough information to solve your problem.
Related
As part of the registration process on a website, I have added mail confirmation. But for some reason, the mail function throws an Internal server error in there.
The strange thing is that if I create a test script, with the exact same email (all the same parameters) it works fine, and sends the email.
The mail is sent from a function in a Class, in case that helps. I didn't post the code because it isn't really relevant, even if I try mail('email#email.com','subject','email'); it fails with the 500 error!
The server error logs don't show anything at all, anyone knows what may cause such a problem?
Technology:
The server is running php through mod_fastcgi, although this problem also happens if I switch to mod_suphp.
Updates:
UPDATE:
I'll try to explain this better, the mail function works perfectly if called from another file, with the same parameters. The problem here is something that combined with the mail function causes an error 500. The rest of the file where it's called is fine too, if I comment the mail function everything works. The way it gets called is an AJAX request to a file that calls a function where the mail is sent (Just in case this helps)
UPDATE 2:
In response to answers so far, here is more information I did not share previously:
OS: CentOS release 5.8
When I say error 500, I mean that the server returns only an HTTP 500 status code.
The server does not show anything in any error log
The most important thing is that if I create a file called test.php, with only mail('address#domain.com','Subject','Message'), it works just fine. When called from this other file, 500 status code returned.
What I am asking is if anyone knows, probably from experience, what could be causing this.
UPDATE 3:
Someone had the same problem yesterday: PHP's mail() function causes a 500 Internal Server Error only after a certain point in the code
UPDATE 4:
After some testing, I have discovered that the 500 stats code is only returned when the script is called via AJAX. If I create a file called test.php, and I simply place the mail function and test it, it works. Calling it via AJAX doesn't, any ideas?
Your question is very confused.
You've not said what operating system you are running on, nor provided details of the configuration: on MSWindows php's mail function acts as an SMTP client. On POSIX OS's (including Linux) it executes a command program to send the email. The SMTP client needs to know the server and port to connect to. The POSIX function needs the config to tell it which program to run.
You keep refering to a 500 error - do you mean an HTTP 500 status code at the browser?
What does the log for the mail program / server show? If this is a posix platform, try changing the php.ini to run a shell script to log actions and parameters.
With the amount of input you have provided, it is very hard to tell, how that error occured.
Error: 500 are Interval Server Errors and can have more than one reasons for occuring.
A malformed php cgi script
An invalid directive in an .htaccess or other config file
Limitation imposed by file system and server software.
May be you are attachcing a file to be to be sent
Missing Line Breaks (\r\n) in the headers
Try every solution listed from this cPanel Forums
After some more hours of testing I have found the problem!
I was using window.location to redirect the user to a new page after the AJAX call was completed, in it's callback function.
Apparently if you modify it after an AJAX call to a php script that uses the mail() function, the server returns a 500 status code in the request
Is there a PHP function or some other way of obtaining the PHP error log as a string?
I need this because I cannot access the error log of a site I am running on someone else's server. - He offered to email me the error log, but that isn't exactly convenient.
Is there some way I could output the error log to a PHP page?
I realize that viewing the entire server's error log is not really going to happen for me. However, I know you can do something like this to email a manual error_log call to yourself:
error_log('A really bad error', 3, 'me#myemail.com');
Is it possible to configure a page to email errors to you instead of displaying them?
On a badly secured server, yes. But on most servers there are two users: apache and [ you ]. You don't have access to the server logs, since they are owned by the apache user (or whichever server you're using).
However, you could probably try it:
echo file_get_contents('/var/log/httpd/error_log');
Note: that's the default location on a RedHat-based apache server. It may be different
Update To reflect the updated question
No, you cannot view the error log with error_log - it is a one-way process that gets handled by the webserver. It only writes the log, but you cannot read it.
You can probably display the errors with this:
ini_set('display_errors', 'On');
error_reporting(E_ALL);
You could even use set_error_handler to handle all warnings and notices (for example, to mail them). But that's pretty much all you can do.
Just installed a nginx server with ubuntu 11.04 and after loading my php program i was writing i noticed that no MYSQL queries run. I get no errores, either from PHP nor MYSQL.
The user my PDO connection uses has all priviledges.
When i change the host to any value, i do not get any error either.
I believe mysql is not showing any connection error. How do i check it's enabled? Just checked mysql.conf and i see nothing related to error reporting. Also looked php.ini and all error options are enabled, i also enabled it in-code.
I have no clue, it's useless to work with no kind of error reporting!
Thanks!
Where are your error logs for nginx? Have you looked in those? Is mysql running? Try service mysql status. PHP should still give you an error though if it can't connect to the database. How do you know the queries are not running? What I mean is, what are the symptoms? Maybe the queries are running but your input is bad?
Most important is to try to isolate the problem. 1) Use curl -v http://your_server to make sure nginx is actually serving the pages. 2) Set up a phpinfo.php file in the root web directory with <? phpinfo(); ?> and check the mysql settings and verify where log files for php are being written 3) Try installing phpmyadmin and see if you can connect to the database using that.
Each one of the above eliminates at least 1 of the elements (your program, PHP, nginx, mysql), helping you to narrow down the cause of your problem.
EDIT: Additional instructions for item 2. You are looking for the php error_log setting. If it is not set, the errors should go to stderr, which in this case I think would be your nginx log files (true at least for apache). You could also check that error_reporting is set to some reasonable value (try error_reporting=E_ALL for now). You can set both of these in your php.ini file, or in your program. See the manual in section PHP Error Handling Runtime Configuration. I would do a sanity check by triggering an error in my program at the beginning of the program and making sure the error shows up in the log file:
trigger_error('Want to be a rock star test message', E_USER_WARNING);
If you see your message, you've got the right log file and you should find your other errors (if any - mysql might not be the problem, could be bad input as I mentioned before).
So I just got a nasty surprise when I deployed some code I thought I'd tested. It would seem there must be some difference between my test machine and my server. The exact same code, featuring a header redirect, worked perfectly on my test machine and not at all on the server. The redirect on the server simply didn't happen, leaving a blank page as a result.
The header is called somewhere in the middle of the script - but nothing will have been output yet. It doesn't output anything until the very end of the script. Long after everything else is run. It buffers everything.
Both server and test machine are running the same PhP version, the same Apache version. Is there something in the configuration files that would allow the header to happen for one and not in the other? Is there something else going on here that would cause it to fail?
EDIT:
Here's the line that sets the header:
public function setRedirect($url) {
header('Location: '.$url);
}
And here's the code that calls that:
$url = new URL('index');
$this->layout->setRedirect($url->toString());
Where URL::toString() always generates a fully qualified domain name, in this case: http://domain/index.php?action=index
I checked both Php and Apache error logs. Nada.
Probably there was some whitespace or other form of output before the header call.
This is only work if you the ini setting output-buffering is on (or if you explicitly start output buffering, but in that case, the redirect should work in both computers).
You can confirm this by turning on error reporting.
Use Fiddler or some other client-side tool to check your headers. Determine that the Location: header is actually being sent. Also, some browsers are picky in the order that headers need to be sent.
I think the most likely explanation is that an error is causing the script to exit on your server, and you have display errors turned off (hence the blank screen). I would suggest checking the Apache error long on your server to see if PHP is putting something in there.
Otherwise you could use a browser extension like LiveHTTPHeaders (for Firefox) to see if the location header is being sent at all, or try debugging the script to see if it's even getting as far as that header call.
I think your server puts some script in your pages to track visitors and give you traffic stats or for a similar purpose. Ideally, you should get an error for this but may be your server has error reporting disabled which gives you a blank page.
I suggest you to run a script with a syntax error and check weather your server has error reporting disabled.
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