Jump to content

code works in php5 but not php4


skis

Recommended Posts

I wrote this code and tested it using a local apache install with php5 installed as a module, and I am now trying to use it on my web host's server which uses apache with php4 installed as cgi. On my local server, this code works perfectly fine. When I try it on my webhost's server, it will return "header didnt work" (one of my or die() strings). Does this have something to do with the versions of php or having php running as cgi instead of as an apache module?

CODE:

correct username and password returns "header didnt work"
i only added the or die()'s for debugging.

<html>
<body bgcolor=#96DCFF>
<?php
//check if login is correct
require('connect.php');
$db_name = "CENSORED";
$tbl_name = "credentials";
$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];
$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$checkadminsql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and admin='1'";
$adminresult = mysql_query($checkadminsql);
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$admincount = mysql_num_rows($adminresult);
if ($count == 1 && $admincount == 1) {
        $isadmin = "1";
        session_register("myusername") or die('session register myusername didnt work');
        session_register("mypassword") or die('session register mypassword didnt work');
        session_register("isadmin") or die('session register isadmin didnt work');
        header("location:queue.php") or die('header didnt work');
}
elseif ($count == 1) {
        session_register("myusername");
        session_register("mypassword");
        header("location:form.php");

} else {
        echo "Wrong Username or Password";
        echo "<br><br><a href=\"login.php\">Try Again</a>";
}
?>
</body>
</html>
Link to comment
Share on other sites

the exact error is "header didnt work", which is coming from:

if ($count == 1 && $admincount == 1) {
        $isadmin = "1";
        session_register("myusername") or die('session register myusername didnt work');
        session_register("mypassword") or die('session register mypassword didnt work');
        session_register("isadmin") or die('session register isadmin didnt work');
        [b]header("location:queue.php") or die('header didnt work');[/b]
}

I have tried using an absolute path instead of a relative path for header() and it does the same thing.
Link to comment
Share on other sites

This is probably me being lazy but...just to rule out the possibility of the header() function not working...try a simple test on a clean php page....

[code]
<?php

  $time = time();
 
  if($time != '') {

  header("Location: http://google.com");

  }

?>[/code]

If that works...then there is likely an error in syntax or logic, in your code.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.