Jump to content

different behavior


BigD

Recommended Posts

My code ran ok on my PC, ran differently after I uploaded to web server. The code checks if user in database. brings up std.php if it is.On web server it passed the check but failed to bring up std.php. it just sits there. <?phpsession_start();include ("mylibrary/login.php");login();$userid = $_POST['userid'];$password = $_POST['password'];$query = "SELECT stdid, classid, lastname, firstname from student where userid = '$userid' and password = '$password'";$result = mysql_query($query);if (mysql_num_rows($result) == 0){ echo "<h2>Sorry, your account was not validated.</h2><br>\n"; echo "<a href=\"std.php\">Try again</a><br>\n";} else{ $_SESSION['store_admin'] = $userid; header("Location: std.php");}?>

Link to comment
Share on other sites

Did you get any errors at all on your home PC server? Usually having a session_start() and then somewhere later in your code you send a header causes the error "Headers already sent". Even echoing before calling the header() function can cause this error. I don't know if this is your case/problem but from the looks of your code, you have a session_start() and then in the else clause you are sending a header. If it finds a user(if num_rows is not equal to 0), it will execute the else clause resulting in the header being sent and getting the "headers already sent" error because of the session_start(). As a side note, for the '$userid' in the query, try removing the single quotes. If it's an integer, you don't need quotes. But first convert $_POST['userid'] to an integer since from my understanding, values in the POST array are treated as strings. So to convert it, you can use the intval() function: $userid = intval($_POST['userid']);

Link to comment
Share on other sites

On my home PC server I did not get Headers already sent error, it just brought up std.php."values in the POST array are treated as strings" does not cause a probelm, why making the change?

Link to comment
Share on other sites

There are other pieces PHP code worked on home PC but just sits there on server PC, no errors displayed. Anyone noticed there are differences when code is running on remote server?

Link to comment
Share on other sites

both server may not posses same configuration. in your case it is obviously different in both of your server. first make sure your error is enabled and set to display all errors that is the point you should start to debug.change the directive based php.ini if it is available or use ini_set() at top most of your script to change the value of there directives"error_reporting=E_ALL""display_error=1" http://php.net/ini_set

Link to comment
Share on other sites

I changed code as suggested, it echoed where it was but the 2 lines added at the beginning did not produce any debug info. Is there another way to go to another panel after displaying "going to next panel"? <?phpini_set('display_errors', '1');ini_set('error_reporting', 'E_ALL');session_start();include ("mylibrary/login.php");login();$userid = $_POST['userid'];$password = $_POST['password'];echo "<h2> userid is $userid</h2>\n";echo "<h2> password is $password</h2>\n";//*********$query = "SELECT stdid, firstname from student where userid = '$userid' and password = PASSWORD('$password')";$query = "SELECT stdid, classid, lastname, firstname from student where userid = '$userid' and password = '$password'";$result = mysql_query($query);if (mysql_num_rows($result) == 0){ echo "<h2>Sorry, your account was not validated.</h2><br>\n"; echo "<a href=\"std.php\">Try again</a><br>\n";} else{ echo "Going to next panel<br>"; $_SESSION['store_admin'] = $userid; header("Location: std.php");}?>

Link to comment
Share on other sites

I have another piece code using the same logic, This one passed control to another panel.<?phpsession_start();include ("../mylibrary/login.php");login();$userid = $_POST['userid'];$password = $_POST['password'];//echo "<h2> userid is $userid</h2>\n";//echo "<h2> password is $password</h2>\n";$query = "SELECT userid from admins where userid = '$userid' and password = PASSWORD('$password')";//echo "SQL $query\n";//$query = "SELECT userid, firstname from admins where userid = '$userid' and password = '$password'";//echo "SQL $query\n";$result = mysql_query($query);if (mysql_num_rows($result) == 0){ echo "<h2>Sorry, your account was not validated.</h2><br>\n"; echo "<a href=\"admin.php\">Try again</a><br>\n";} else{ $_SESSION['store_admin'] = $userid; header("Location: admin.php");}?>

Link to comment
Share on other sites

I captured PHP variables/values on both home pc local PHP adm and web server. I plan to change home PC PHP values to be the same as web serverso problems on remote can be tested locally. I am not experienced on PHP. Anyone have done similar things please advise. Does ini file need to be the same? Thanks.

Link to comment
Share on other sites

I changed code as suggested, it echoed where it was but the 2 lines added at the beginning did not produce any debug info. Is there another way to go to another panel after displaying "going to next panel"?
It wont show anything unless there is error. if there is error generating it would show you. location header will redirect instantly.header("refresh:5;url=http://someurl.com"); or meta redirects will do delayed redirection. yes it is better to have same setting in both server.but in case of any misbehave if error reporting is enabled it will tell you all which setting is causing what.
echo "Going to next panel<br>";$_SESSION['store_admin'] = $userid;header("Location: std.php");
you cant send header after you make an output unless output buffering is enabled by default in your setting. so if that setting is different in two server it will throw some error in that case and header wont work.
Link to comment
Share on other sites

Folks, I resolved all the problems and got everything working on remote server. Let me tell you what I did.my local server has version 3.3.9 and remote server has version 3.4.10.1 I do not know it is the software versiondifferences or the PHP variables value differences; they behave differently.I did not change any PHP variable values.On remote server, goto causes syntax error, echo causes header() not transfer control, it is case sensitive on panel names.error goes to error-log, not screen.I modified my code to make it work on remote server.If you know what causes those behavior on remote server, please share it.This is a great place to work issues. Thanks folks.

Link to comment
Share on other sites

Is that really PHP version 3, or is that a typo for version 5? Goto requires PHP 5.3 or greater. Sending a header after sending other output always causes an error unless output buffering is enabled. Output buffering can be enabled in php.ini, or manually in a script. Linux servers are case-sensitive regarding filenames, Windows servers are not. Error reporting settings are set in php.ini and can also be set in a script. The log_errors setting says whether to log errors, and the error_log setting says which error log to use.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...