Jump to content

local server vs online server


funbinod

Recommended Posts

why is my scripts not working on online server while it is working fine on local server????

like

 

this is working fine on my local server but while online it gives error regarding session_start() and header informations.

 

I don't know what is this. please guide.......

Edited by funbinod
Link to comment
Share on other sites

When you call session_start() you have to make sure that no content was printed before it. No echo statements and nothing outside of the <?php ?> block. Make sure there are no spaces or line breaks at the beginning of your code. The "byte order mark" might also be the cause for this. If your editor has the option, be sure to tell it to save as UTF-8 without BOM

 

The reason that your computer doesn't show the message might be that it's set to not display warnings.

Link to comment
Share on other sites

That why I compose online when it's going to be used on on. Otherwise, there's always at least one issue.

Link to comment
Share on other sites

I find it much more practical to develop locally while knowing what the final production environments will run on. rsync-ing or FTPing just to see changes adds a lot of overhead to development cycle time. I would rather just know my environments and plan accordingly.

 

Naturally, something always happens, no matter how well you think you know your environments. Might as well develop as efficiently as you can then.

Link to comment
Share on other sites

if my local site is opening FINE just because I've disabled error displayed setting, shouldn't the online page open along with error messages?????? but my page is displaying only errors.......

please have a look at these pages...

 

http://mimosa-nepal.com/mimosa_cashier (my online page)

and

http://103.28.84.9/mimosa_cashier (my local server)

 

use the following username and password to login---

 

username: testuser

password: TestPassword1

 

and please help me resolve the problem....

Link to comment
Share on other sites

if my local site is opening FINE just because I've disabled error displayed setting, shouldn't the online page open along with error messages?

No, not if the thing that is breaking is a redirect.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/funbinod/public_html/mimosa_cashier/header.inc.php:64) in /home/funbinod/public_html/mimosa_cashier/classUser.php on line 15

The part in bold tells you where the output is being sent. If you are going to redirect anyway, then there's no reason to even send any output, the user will never see it. It looks like you're trying to include files that have output in them even though you're going to redirect. If you're going to redirect then just redirect, don't include anything. You also need to start the session before sending any output as well.Check here for more information:http://w3schools.invisionzone.com/index.php?showtopic=12509&p=96607#entry96607http://w3schools.invisionzone.com/index.php?showtopic=44106
Link to comment
Share on other sites

according to the suggestions, I changed the position of include files to the top on the header.inc.php and it fixed the error regarding session_start. but still having the problem regarding header... I reviewed my code and thought it is referring me to the following portion...

$laquery = mysqli_query($connect, "SELECT lastActive FROM user WHERE cid=$cid AND uid=$uid") or die ("Error: ".mysqli_error($connect));$larow = mysqli_fetch_object($laquery);$lastActive = $larow->lastActive;$now = date('Y-m-d H:i:s');//echo strtotime($now) - strtotime($lastActive);if (strtotime($now) - strtotime($lastActive) > 1200) {	mysqli_query($connect, "UPDATE user SET isloggedin='N' WHERE cid=$cid AND uid=$uid") or die("Error: ".mysqli_error($connect));	$user->logout();	$_SESSION['timeout'] = "Timeout!";	die(header("location: login.php"));} else if (strtotime($now) - strtotime($lastActive) < 1200) {	mysqli_query($connect, "UPDATE user SET lastActive = now() WHERE cid=$cid AND uid=$uid") or die ("Error: ".mysqli_error($connect));}

the header information on line 83 is only if some condition apply so I think this should not be a mistake. please guide me if i should not use this or suggest me anything (or this is not the problem the error message referring!!!!)

Link to comment
Share on other sites

much harassing!

 

(output started at /home/funbinod/public_html/mimosa_cashier/header.inc.php:64)

I couldn't find where is this line 64! :(

 

on the whole header.inc.php file there is only one header included (at line 83) and this is only IF it found some CONDITION. is doing this illegal?? or i'm pointed towards elsewhere?

Link to comment
Share on other sites

sorry! I think I need to submit some more lines from my code...

<script language="javascript">function checkName(ob) {	var invalidChars = /[^0-9"a-z.- /)(]/gi	if(invalidChars.test(ob.value)) {		ob.value = ob.value.replace(invalidChars,"");		alert('Please use only "a-z", "0-9", ".", "-", "(", ")", """, AND "/" !');	}}</script><?php// check last active$info = "SELECT * FROM clients WHERE cid=$cid";$inforesult = mysqli_query($connect, $info) or die ("Error: " . mysqli_error($connect));$inforow = mysqli_fetch_array($inforesult);$laquery = mysqli_query($connect, "SELECT lastActive FROM user WHERE cid=$cid AND uid=$uid") or die ("Error: ".mysqli_error($connect));$larow = mysqli_fetch_object($laquery);$lastActive = $larow->lastActive;$now = date('Y-m-d H:i:s');//echo strtotime($now) - strtotime($lastActive);if (strtotime($now) - strtotime($lastActive) > 1200) {	mysqli_query($connect, "UPDATE user SET isloggedin='N' WHERE cid=$cid AND uid=$uid") or die("Error: ".mysqli_error($connect));	$user->logout();	$_SESSION['timeout'] = "Timeout!";	die(header("location: login.php"));} else if (strtotime($now) - strtotime($lastActive) < 1200) {	mysqli_query($connect, "UPDATE user SET lastActive = now() WHERE cid=$cid AND uid=$uid") or die ("Error: ".mysqli_error($connect));}?><table cellspacing="0" align="center" style="padding:0; border:none; width:1000px;">........................................................

and sorry! after some edit the line 64 is now line 67 (you can check the link again :P)

 

and there is only one line for new header at line 82. there is no header include throughout the whole script.

that's why I said I didn't find line 64 (now 67)

Edited by funbinod
Link to comment
Share on other sites

well now it's pretty clear. you have code before the opening <php tag; it's that entire <script> block. That is considered output.

Link to comment
Share on other sites

well! it seems to be solved now. thank u.

 

but it stroke another problem now. there became date time problem. I used MySQL function 'now()' to update user lastActive and then calculated the time elapsed with the php date function. but it differed in execution. I think MySQL now() returned server date time and php date returned local date time. that's why each time i'm login it exceeds the max inactive time and returns logout function and redirects to login page...

$laquery = mysqli_query($connect, "SELECT lastActive FROM user WHERE cid=$cid AND uid=$uid") or die ("Error: ".mysqli_error($connect));$larow = mysqli_fetch_object($laquery);$lastActive = $larow->lastActive;$now = date('Y-m-d H:i:s');//echo strtotime($now) - strtotime($lastActive);if (strtotime($now) - strtotime($lastActive) > 1200) {	mysqli_query($connect, "UPDATE user SET isloggedin='N' WHERE cid=$cid AND uid=$uid") or die("Error: ".mysqli_error($connect));	$user->logout();	$_SESSION['timeout'] = "Timeout!";	die(header("location: login.php"));} else if (strtotime($now) - strtotime($lastActive) < 1200) {	mysqli_query($connect, "UPDATE user SET lastActive = now() WHERE cid=$cid AND uid=$uid") or die ("Error: ".mysqli_error($connect));}

I've assigned d default timezone

date_default_timezone_set("Asia/Kathmandu");

how can I adjust this. I want to calculate the inactive time regarding server time....

Edited by funbinod
Link to comment
Share on other sites

Both of them use server time, but they might be using different default time zones. In PHP you can use date_default_timezone_set to set the default. For MySQL, every time you connect to the database the first query you need to send is one to set the time_zone option. Note that it won't change any data already in the database.http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

Link to comment
Share on other sites

encountered another problem but couldnot find out the reason...

can u please help me find out the exact problem here in the following code regarding function.session_start

<?phprequire_once('functions.php');	if(!$connect) {		echo 'ERROR: Could not connect to the database.';	} else {		if(isset($_POST['queryString'])) {			$queryString = $connect->real_escape_string($_POST['queryString']);			if(strlen($queryString) >0) {				$query = $connect->query("SELECT name FROM account WHERE name LIKE '%$queryString%' AND cid=$cid LIMIT 10");				if($query) {					echo '<h3>Registered Accounts</h3>';					while ($result = $query ->fetch_object()) {	         			echo '<li>'.$result->name.'</li>';	         		}				} else {					echo 'Error encountered!';				}			} else {			}		} else {			echo 'you dont have permession to open this page!';		}	}?>

inside functions.php I've included another file named classUser.php and in that code at line 15 it has session_start() and the error messege is pointing towards this line as [source line] and the first line of the above script as [output line]....

Link to comment
Share on other sites

If it's the first line, before the PHP code, then you probably have an empty line. That will cause that problem. If it's not an empty line then you might be saving the file as a UTF file with a BOM at the beginning. You'll need to save the file without the BOM. Some editors have specific options for leaving out the BOM. If you need an editor then look into Sublime Text, it saves UTF files without the BOM by default.

  • Like 1
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...