View Full Version : php PDO codes runs on windows but does not run on linux
mutago
10-12-2013, 04:40 PM
During development,
I develop my php codes using PDO on windows via Xammp server.
now when i deployed it on the server, some of them run , some did not run at all.
what could be the problem.
1: Is there something that i need to enable.
2: Is php PDO not supported on this server
3: Why did all my applications runs execellent on windows via Xammp server but does not run on linux with webhosting account
Take a look at the code below
<?php
error_reporting(0);
?>
<?php
require("pdodatabase.php");
$usern=strip_tags($_POST['usern']);
$pass=strip_tags($_POST['pass']);
$ip_adres = strip_tags($_SERVER['REMOTE_ADDR']);
$statement = $db->prepare('INSERT INTO report (offender,offence,reporter_ip)
values
( :offender,:offence,:reporter_ip)');
if($statement->execute(array(
':offender' => $usern,
':offence' => $pass,
':reporter_ip' => $ip_adres
))){
header("location: sucess.php");
}else{
header("location: fail.php");
}
?>
This code above runs on my Xammp server perfectly and displays a success.php page but here it runs but cannot display the success page.
Almost all my application refuses to run.
Thank You
jscheuer1
10-12-2013, 05:07 PM
get rid of:
<?php
error_reporting(0);
?>
and:
else{
header("location: fail.php");
}
and you might be able to see the error.
1. You can check if PDO is supported on your server (and what version/library/drivers are available) by looking at the output of phpinfo (http://php.net/phpinfo).
2. Yes, Windows and Linux are very different. PHP does an okay job at abstracting this, but there are things that simply can't be ignored. It takes a lot of study to figure out what all those things are.
A quicker, and more sure, solution is to make your development environment match your production environment more closely. If you're deploying to a Linux server (most people are), then write your code on a Linux server. Download Ubuntu and Xampp and dual-boot. It's not complicated (you don't even have to install Ubuntu if you don't want to - it can run from a flash drive).
3. You should never find yourself in a situation where you need to use strip_tags. You should turn magic quotes off instead (talk to your host about how to do this). Better yet, upgrade to php 5.4 and never worry about it again. If magic quotes are "on" and your host won't let you turn them off, find a different host. If you have no choice, then you should check if magic quotes is on or not and handle tag-stripping at the beginning of your script, when the data first comes in, not on a one-by-one basis when you use each value.
--------------------------------
If you want more help with your specific issue, then you need to explain your problems more clearly. Tell us what you expect, what happens instead, and what error messages you receive (hint: turning off error reporting is good for live sites, but very bad for figuring out problems). Be as detailed as possible.
mutago
10-12-2013, 08:27 PM
All my application does not show any error on the linux. is just that some code will run while others does not. Even those that run just run partiallly. The code above inserts records into the server on the linux server without displaying eg. success.php page. On my windows 7 via xammp server. the above code runs 100% correct even if its displayed 1000's time. I think my hosting server does not fully support PDO or the Linux itself. Am just in a mess for my school assignment.
I think i regret learning PDO in the first place. If i cannot find any windows shared hosting company that uses Xammp server with unlimited space and bandwidth. I will just go back to mysql deprecated functions and try to secure
my application against SQL INJECTION using mysql_real_escape_string();
Thanks for help rendered so far
jscheuer1
10-12-2013, 08:52 PM
Your application will not show any error until you remove:
<?php
error_reporting(0);
?>
Once you remove that, if there are any errors you should be able to see them.
All my application does not show any error on the linux.
As John says, that's because you are expressly ignoring the error output. Use error_reporting( -1 ); ini_set( 'display_errors',1 ); instead.
If your error is occurring in MySQL, you may also need to use the appropriate PDO methods to check (in fact, you should be doing so anyway).
The code above inserts records into the server on the linux server without displaying eg. success.php page.
If it inserts the records successfully, then the problem is probably in the part that follows:
header("location: sucess.php");
If you look up the manual page for header() (http://php.net/header), you'll see that you are not using the correct form for the header $string. The fact that it works on your local server is probably an accident.
I think my hosting server does not fully support PDO or the Linux itself.
Even as bad as many hosts are, I doubt that is the case.
I think i regret learning PDO in the first place. If i cannot find any windows shared hosting company that uses Xammp server with unlimited space and bandwidth. I will just go back to mysql deprecated functions and try to secure my application against SQL INJECTION using mysql_real_escape_string();
If you find a hosting company that runs xampp on Windows (I've never heard of such a thing), you need to avoid them. The xampp package is fine for local development on your own computer, but it is not at all suitable for production (live sites).
mutago
10-13-2013, 05:30 AM
i think problem lies here also
header("location: sucess.php");
can you give an example od a working header
thank you
can you give an example od a working header
Did you look at the php manual page (http://php.net/header)?
mutago
10-13-2013, 08:52 AM
the header() is the problem. it does not return success.php page.
what am seeing in the manual is the same as this above
echo 'submitted';
it will print submitted when echoed but cannot redirect to sucess.php
header("location: sucess.php");
mutago
10-13-2013, 08:53 AM
This is all about linux issue
mutago
10-13-2013, 10:10 AM
resolved. you need to enable output_buffering = on
or programtically set it in the first line of all the php codes
<?php ob_start(); ?>
In conclusion, am still working on the rest of the code to ensure workability and will get back here after i might have finish.
DynamicDrive: You guys are extremely wonderful
Thank you
mutago
10-13-2013, 11:38 AM
This fix the problem
I loaded all pdo_mysql module in the php.ini at root directory
At php.ini enable output_buffering by setting it to on or value 4096
or programmatically embed it on every first line of the php
<?php ob_start(); ?>
and the last or very bottom of the page
<?php ob_end_flush(); ?>
The settles the whole thing. I can now enjoy PDO
Thanks all. You guys are great. Am still working on other PDO codes and will get back should any thing goes wtong
You guys are great
This fix the problem
I loaded all pdo_mysql module in the php.ini at root directory
At php.ini enable output_buffering by setting it to on or value 4096
or programmatically embed it on every first line of the php
<?php ob_start(); ?>
and the last or very bottom of the page
<?php ob_end_flush(); ?>
The settles the whole thing. I can now enjoy PDO
Thanks all. You guys are great. Am still working on other PDO codes and will get back should any thing goes wtong
You guys are great
I'm glad you figured it out.
If your question has been answered, please mark your thread "resolved":
On your original post (post #1), click [edit], then click [go advanced]. In the "thread prefix" box, select "Resolved". Click [save changes].
Two things that might be helpful for you in the future:
1) The fact that you have to use output buffering means that you have output being sent to the browser before you try to use header(). Using ob is just a monkeypatch (and will still fail if you ever happen to output more than 4096 bytes (your chunk size) before you try to set any headers). The real solution is to re-organize the order in which your script is written, so that all of your output happens after all of your program logic. Writing "PHP First" will also mitigate other problems in the future.
2) If you did not fix your Location header string, you should still do so. Not all browsers will interpret what you have the same way, and some will ignore it because it is not well-formed.
Note:
HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path ...
Your current example would be correctly written like so:
Location: http://example.com/absolute/path/to/sucess.php
Strangeplant
10-15-2013, 07:31 PM
Looks to me it looks like the variable $statement is not being evaluated to a boolean (true/false), and so whatever depends on this being 'true' is failing. To me, it is better to do this:
$statement->execute(array(':offender' => $usern,':offence' => $pass,':reporter_ip' => $ip_adres));
# test your boolean here
if ($statement) {
header("location: sucess.php");
}else{
header("location: fail.php");
}
the OP has stated that he found a solution, and this thread is starting to attract a lot of spam, so I'm going to close this thread. @mutago, if you have another question, you are welcome to start another thread.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.