Jump to content


Photo

code works in php5 but not php4


  • This topic is locked This topic is locked
6 replies to this topic

#1 skis

skis
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 October 2006 - 08:44 PM

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>


#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 24 October 2006 - 08:53 PM

Can you please post the exact error you get? I don't think I've seen the "Header didn't work" error yet. :-)
PHP Ninja

#3 skis

skis
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 October 2006 - 09:04 PM

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');
        header("location:queue.php") or die('header didnt work');
}

I have tried using an absolute path instead of a relative path for header() and it does the same thing.

#4 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 24 October 2006 - 09:15 PM

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....

<?php

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

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

  }

?>

If that works...then there is likely an error in syntax or logic, in your code.
PHP Ninja

#5 skis

skis
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 October 2006 - 09:24 PM

That does work both locally and on the web host. I will continue going over my code to try and figure out why this isn't working.

#6 skis

skis
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 October 2006 - 09:53 PM

I cannot find what is wrong here, can someone please help me proofreading my code?

#7 skis

skis
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 October 2006 - 10:34 PM

Nevermind, I got it now. It was because I was sending <html> before the header. Guess I should read stickies...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users