PDA

View Full Version : Getting WindowsNT scripts to work on Unix?


bleachedtips
09-05-2002, 05:30 PM
I don't know what i'm doing wrong but my PHP scripts that work fine on Windows NT never work on Unix.

Like take this code for example:


<? if ($action == "setcookie") {
setcookie("chocolatechip", $alias, 3600);
header('Location: login.php');
} elseif ($action == "unsetcookie") {
setcookie("chocolatechip", $alias, -3600);
header('Location: login.php');
} ?>

<? if (isset ($chocolatechip)) { ?>
<html><body>
Welcome back, <? echo $_COOKIE["chocolatechip"]; ?> | <a href="login.php?action=unsetcookie">Forget Me</a>
</body></html>
<? } else { ?>
<html><body>
<form action="login.php?action=setcookie" method="post">
<input type="text" name="alias">
<input type="submit" name="setcookie" value="Remember Me">
</form>
</body></html>
<? } ?>


What it does it set a cookie with the users name in it, so it remembers them the next time they visit the page. And it works on my NT server, but when I put it on the Unix one, all I get is this:

Welcome back, | Forget Me

The cookie part doesn't work. I've had this problem with every script i've made so it must be something i'm just missing. I'm pretty new to PHP so can someone explain this to me?

Thanks a bunch

Spookster
09-05-2002, 10:31 PM
Does your linux server php installation have register_globals set to on or off?

bleachedtips
09-12-2002, 08:45 PM
I'm not sure, I was using coolfreepages.com as a host, which has PHP4 support, but i'm guessing they have that off. What good is having PHP support if you can't do much with it...

Does anyone know of another free php host?

Spookster
09-12-2002, 09:06 PM
Well that really doesn't change much other than how you refer to the variables.

For instance if you were grabbing variable values from a form:

Old way:

$value1 = $HTTP_POST_VARS["value1"];

New way:

$value1 = $_POST["value1"];

The newest versions of php have register globals set to off by default so as to gradually deprecate that way of doing things and start referring to variables this way.

also variables won't be immediately available so if something was submitted via a form you can't just say $value1 and already have it filled with the value. That's not good programming style anyways as you should always declare you variables and initalize them before you refer to them throughout your code.