• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

Moving PHP scripts from a Windows environment to Linux

Dear Experts,

I'm pretty new to Linux but I can manage easy tasks like starting up and shutdown, installing software and saving files.

Anyway, my question is how do I make my PHP scripts developed in a Windows environment work with Linux?

I used sessions to login users into my site but I had to edit the php.ini file to make it work first. I'm not sure what the problem is really, but I can login, get into the first page (members homepage), but when I try to click on other pages that check if the session is valid, I'm redirected to the login page.

I'm using Mandrake 9.2, Apache 2.0, MySQL 4.0.18, and PHP 4.3

Thanks in advance!
0
jericotolentino
Asked:
jericotolentino
  • 4
  • 4
1 Solution
 
Marcus BointonCommented:
Firstly make sure all your script files have unix-format line breaks.

Apart from that, the usual sticking point of moving platforms is paths - paths like 'c:\stuff' will be meaningless on Linux, so check all your paths.

It sounds like your sessions are not starting - check that session files are being created in /tmp (or wherever you have told them to go in php.ini). We need more detailed info before we can be much help.
0
 
jericotolentinoAuthor Commented:
Thanks for your reply. I checked the /tmp folder and there were files there. There's a file there starting with session and followed by alphanumeric characters. I'm not sure that's an indication that the sessions were starting but I saw a lot of those on Windows.

My paths are ok though. The page is redirecting well and the includes are all processed fine.

I'm not also sure by what you mean by "unix-format line breaks." Are you talking about <br />?

Sorry, this is a little too hard for me...
0
 
robknowlesCommented:
About the only advice I can give is to check through your php.ini file and double check the session settings, check they are all correct and make sense, then make sure the folder specified to store the sessions files in a) exists and that the web server has the proper permissions to write to the folder.

Next thing is to use a simple couple of php pages (not the one's you're already using) just to check if sessions are working, e.g. have the page write something to the session, navigate to the second page and see if the sessions have indeed carried over.  If you find that they are working fine, then it's something connected with the php scripts you wrote for the windows system you were previously using, however if they don't work obviously it's still a session/php issue.

Hope that might have helped some, but you've probably already tried these anyways. cheers
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Marcus BointonCommented:
No, not <br> - that's an HTML thing. Different OSs traditionally use different characters to denote ends of lines in plain text files. Windows uses a carriage return (ASCII 13, also known as 'CR') followed by a line break (ASCII 10, aka 'LF'), collectively known as CRLF. UNIX uses just LF, and just for completeness, MacOS uses just CR (though Mac OS X, as a UNIX platform, uses LF). Most modern text editors (that excludes notepad) can cope with multiple line break formats, but sometimes compilers and languages like PHP cannot. Generally it's a good idea to match your line breaks to the platform you're on.

As robknowles says, try a simple test to make sure it's the sessions themselves that are broken and not something else in your script:

<?php
session_start();
array_key_exists('test', $_SESSION) ? $_SESSION['test']++ : $_SESSION['test'] = 0;
print "test = {$_SESSION['test']}\n");
?>

If that works (should print a number that increments every time you hit it), then you know that sessions are not the problem.
0
 
jericotolentinoAuthor Commented:
Hi,

I tried Squinky's script and at the start I got some errors but eventually figured it out. :-)

The page prints out the numbers and increments everytime.

One more thing, where do I find the php.ini file in Linux?

Thanks!
0
 
Marcus BointonCommented:
Ah, sorry, there is a stray ) in it...

On linux php.ini usually in /etc/php.ini. phpinfo() will also tell you where it's looking.
0
 
Marcus BointonCommented:
If that script is running ok, and numbers are incrementing, then sessions are definitely working and the problem must be elsewhere in your code. I'd check through your authentication code.
0
 
jericotolentinoAuthor Commented:
Hi,

Maybe I'm being a little stupid today, but I can't find what's wrong with the authentication code.

Here's checkLogin.php, and it just checks if the username and password are in the database...

---------

<?

if((!$_POST['username']) || (!$_POST['password'])) {
header("location: login.html");
}
else {

include 'include/connect.inc';

$sql = "SELECT * FROM users WHERE username = '{$_POST[username]}' AND password = '{$_POST[password]}'";
$result = @mysql_query($sql);
if (!$result) {
echo('<p>Error retrieving data:  ' . mysql_error() . '. <br /><br />I don\'t like this, do you?</p>');
exit;
}

$num = mysql_num_rows($result);
if ($num < 1) {
header("location: login.html");
exit;
}

session_start();
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
header("location: members_home.php");
}
?>

----------------

Now, I can get into member's home, but where the user's name is supposed to appear in the welcome section, is just a space. So it just shows "Welcome !" instead of "Welcome (username)!"

Then when I click on other links, there's the part where I get sent back to the login screen.

Is there something wrong with these lines below?

<?
session_start();

if((!$_SESSION['username']) || (!$_SESSION['password'])) {
header("location: login.html");
exit;
...rest of script...
?>

--------------
0
 
jericotolentinoAuthor Commented:
Hi,

Never mind guys. I decided to do something else instead. Quite unexpectable, but it worked.

In the login check script, the variables were still there but somehow in the members home page, it was gone. So I just made a new variable and set its value to the session variable. Everything works fine now.

Many thanks for your kind help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now