Jump to content

Archived

This topic is now archived and is closed to further replies.

skis

code works in php5 but not php4

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>

Share this post


Link to post
Share on other sites
Can you please post the exact error you get? I don't think I've seen the "Header didn't work" error yet. :-)

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I cannot find what is wrong here, can someone please help me proofreading my code?

Share this post


Link to post
Share on other sites
Nevermind, I got it now. It was because I was sending <html> before the header. Guess I should read stickies...

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.