Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

CGI Error

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

CGI Error

Postby djdejan » Fri Sep 05, 2003 7:18 am

Hi,
I have a problem with PHP! I use PHP 4.2.1 on Windows 2000 Server and IIS 5.0. Script which I sent works OK on Windows XP and same PHP!

Code: Select all
PAGE FUNKCIJE.PHP
---------------------

<?php

/////////////////////////////////////////////////////////////
// Funkcija za logovanje
////////////////////////////////////////////////////////////
function login($korisnik, $server, $baza)
{
include("includes/config.php");
if(empty($server) || empty($baza) || empty($korisnik))
   {
   global $errormessage;
   $errormessage="$error_style Sva polja moraju biti popunjena!";
   }
else
   {
   include("includes/config.php");
   $konekcija = new COM("ADODB.Connection") or die("Ne mogu startovati ADO");
   $konekcija->Open("Provider=SQLOLEDB; Data Source=$db_host; Initial Catalog=$db_name; User ID=$db_username; Password=$db_password");
   com_set($konekcija,'CursorLocation', '3');
   com_set($konekcija,'CursorType', '2');
   com_set($konekcija,'LockType', '3');
   $upit_izvrsi=$konekcija->Execute("SELECT * FROM v_WEBUserLogin WHERE (SifUSr='$korisnik') AND (IPAdress='$server') AND (DatabaseName='$baza')");
   $num_rows=$upit_izvrsi->RecordCount();
   if($num_rows===0)
      {
      global $errormessage;
      $errormessage="$error_style Podaci koje ste uneli nisu ispravni!";
         $konekcija->Close();
      }   
   else
      {
      while (!$upit_izvrsi->EOF)
      {
      setcookie("server_cookie", $server, 24);
      setcookie("baza_cookie", $baza, 24);
      setcookie("korisnik_cookie", $korisnik, 24);
      $new_counter=$upit_izvrsi->fields["UsrCnt"]->value+1;
      $konekcija->Execute("UPDATE v_WEBUserLogin SET SadUla={ fn NOW() }, UsrCnt='$new_counter' WHERE (SifUSr='$korisnik')");      
      session_start();
      session_register("session_username", "session_db_host", "session_db_name", "session_db_username", "session_db_password");
      global $session_username, $session_db_host, $session_db_name, $session_db_username, $session_db_password;
      $session_username=$korisnik;
      $session_db_host=$upit_izvrsi->fields["IPAdress"]->value;
      $session_db_name=$upit_izvrsi->fields["DatabaseName"]->value;
      $session_db_username='sa';
      $session_db_password='dejan333';
      $upit_izvrsi->movenext();
      }      
   $konekcija->Close();
   header("Location: index.php");
      }
   }
   
}

/////////////////////////////////////////////////////////////
// Funkcija koja proverava da li je korisnik logovan -samo korisnicko ime
////////////////////////////////////////////////////////////
function user_check()
{
include("includes/config.php");
session_start();
global $session_username, $session_db_host, $session_db_name;
if(empty($session_username))
   {
   header("Location: login.php");
   die();
   }
else
   {
   include("includes/config.php");
   $konekcija=mssql_connect($db_host, $db_username, $db_password);
   mssql_select_db($db_name, $konekcija);
   $upit="SELECT * FROM v_WEBUserLogin WHERE (SifUSr='$session_username') AND (IPAdress='$session_db_host') AND (DatabaseName='$session_db_name')";
   $upit_izvrsi=mssql_query($upit, $konekcija);
   if(mssql_num_rows($upit_izvrsi)===0)
      {
      $konekcija->Close();
      header("Location: login.php");
      die();
      }   
   }
}

/////////////////////////////////////////////////////////////
// Funkcija za LogOff
////////////////////////////////////////////////////////////
function logoff()
{
session_start();
global $session_username;
include("includes/config.php");
$konekcija = new COM("ADODB.Connection") or die("Ne mogu startovati ADO");
$konekcija->Open("Provider=SQLOLEDB; Data Source=$db_host; Initial Catalog=$db_name; User ID=$db_username; Password=$db_password");
$upit_izvrsi=$konekcija->Execute("SELECT * FROM WEBUser WHERE SifUsr='$session_username'");
while (!$upit_izvrsi->EOF)
      {
      $zadula=date("d.m.Y H:i",$upit_izvrsi->fields["SadUla"]->value);
      //echo 'hghjgj';
      $konekcija->Execute("UPDATE WEBUser SET ZadUla='$zadula', ZadIzl={ fn NOW() } WHERE (SifUSr='$session_username')");
      $upit_izvrsi->movenext();
      }
      $konekcija->Close();
session_destroy();
}

///////////////////////////////////////////////
// Funkcija za prikaz broja u obliku brojaca //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function number_counter($number)
{
include("includes/config.php");

$milioni=intval($number/1000000);
$stotinehiljada=intval(($number-$milioni*1000000)/100000);
$desetinehiljada=intval(($number-$milioni*1000000-$stotinehiljada*100000)/10000);
$hiljade=intval(($number-$milioni*1000000-$stotinehiljada*100000-$desetinehiljada*10000)/1000);
$stotine=intval(($number-$milioni*1000000-$stotinehiljada*100000-$desetinehiljada*10000-$hiljade*1000)/100);
$desetice=intval(($number-$milioni*1000000-$stotinehiljada*100000-$desetinehiljada*10000-$hiljade*1000-$stotine*100)/10);
$jedinice=intval($number-$milioni*1000000-$stotinehiljada*100000-$desetinehiljada*10000-$hiljade*1000-$stotine*100-$desetice*10);


$slikamilioni="images/counter/$milioni.gif";
$slikastotinehiljada="images/counter/$stotinehiljada.gif";
$slikadesetinehiljada="images/counter/$desetinehiljada.gif";
$slikahiljade="images/counter/$hiljade.gif";
$slikastotine="images/counter/$stotine.gif";
$slikadesetice="images/counter/$desetice.gif";
$slikajedinice="images/counter/$jedinice.gif";
print("<img border=0 src=$slikamilioni>");
print("<img border=0 src=$slikastotinehiljada>");
print("<img border=0 src=$slikadesetinehiljada>");
print("<img border=0 src=$slikahiljade>");
print("<img border=0 src=$slikastotine>");
print("<img border=0 src=$slikadesetice>");
print("<img border=0 src=$slikajedinice>");

}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// FUNKCIJE VEZANE ZA SETOVANJE SESIJA
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
function mysess_open($aSavePath, $aSessionName)
{
   return True;
}

function mysess_close()
{
   return True;
}

function mysess_read($aKey)
{
   include("includes/config.php");
   $konekcija=mssql_connect($db_host, $db_username, $db_password);
   mssql_select_db($db_name, $konekcija);
   $upit="SELECT SessionValue FROM WEBSessions WHERE SessionID='$aKey'";
   $upit_izvrsi=mssql_query($upit, $konekcija);
   if(mssql_num_rows($upit_izvrsi)==1)
   {
      while($aRow=mssql_fetch_array($upit_izvrsi))
      {
         $update_upit="UPDATE WEBSessions SET LastRead={ fn NOW() } WHERE SessionID='$aKey'";
         mssql_query($update_upit, $konekcija);
         return $aRow['SessionValue'];
      }
   }
   else
   {
      $upit="INSERT INTO WEBSessions (SessionID, LastUpdated, LastRead, SessionValue) VALUES ('$aKey', { fn NOW() }, { fn NOW() }, '')";
      mssql_query($upit, $konekcija);
      return "";
   }
}

function mysess_write($aKey, $aVal)
{
   include("includes/config.php");
   $konekcija=mssql_connect($db_host, $db_username, $db_password);
   mssql_select_db($db_name, $konekcija);
   $upit="UPDATE WEBSessions SET SessionValue='$aVal', LastUpdated={ fn NOW() }, LastRead={ fn NOW() } WHERE SessionID='$aKey'";
   mssql_query($upit, $konekcija);
   return True;
}

function mysess_destroy($aKey)
{
   include("includes/config.php");
   $konekcija=mssql_connect($db_host, $db_username, $db_password);
   mssql_select_db($db_name, $konekcija);
   $upit="DELETE FROM WEBSessions WHERE SessionID='$aKey'";
   mssql_query($upit, $konekcija);
   return True;
}

function mysess_gc($aMaxLifetime)
{
   /*include("includes/config.php");
   $konekcija=mssql_connect($db_host, $db_username, $db_password);
   mssql_select_db($db_name, $konekcija);
   $upit="DELETE FROM WEBSessions WHERE { fn NOW() }-LastRead>$session_life";
   mssql_query($upit, $konekcija);
*/
return True;
}

session_set_save_handler("mysess_open", "mysess_close", "mysess_read", "mysess_write", "mysess_destroy", "mysess_gc");
?>




PAGE INDEX.PHP
---------------------

<?php
include("includes/funkcije.php");
user_check();
if(!empty($action))
{
   switch($action)
      {
      case 'logoff':
      logoff();
      break;
      }
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/negativ.dwt.php" codeOutsideHTMLIsLocked="false" -->

<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>OmniaSoft WEB Business System</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<style type="text/css">
<!--
.login {
   background-repeat: repeat-x;
   background-image:  url(images/loginbg.jpg);
   background-position: bottom;
   border: 0;
}
html{
   margin: 0;
   border: 0px 0;
}
-->
</style>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body bgcolor="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="html">
  <tr>
    <td width="13%" height="10%" rowspan="2" align="center" valign="middle" bgcolor="#000000">
      <font color="#FFFFFF" size="4" face="Tahoma"><strong><?php echo date("d.m.Y.");  ?></strong></font>
      <div align="center">
        <select size="1" name="D1" style="border:1px solid #C0C0C0; font-family: Verdana; font-weight: bold; color:#FF0000; font-size:18px; padding-left:4; padding-right:4; padding-top:1; padding-bottom:1; background-color:#000000">
          <option>2003</option>
          <option>2002</option>
        </select>
        <?php

// STAMPA POSLOVNE GODINE

include("includes/config.php");
session_start();
$konekcija = new COM("ADODB.Connection") or die("Ne mogu startovati ADO");
$konekcija->Open("Provider=SQLOLEDB; Data Source=$db_host; Initial Catalog=$db_name; User ID=$db_username; Password=$db_password");
$upit_izvrsi=$konekcija->Execute("SELECT * FROM v_WEBUserLogin WHERE (SifUSr='$session_username') AND (IPAdress='$session_db_host') AND (DatabaseName='$session_db_name')");
?>
        <font color="#FFFFFF" size="4" face="Tahoma"><strong> </strong></font></p>
      </div></td>
    <td width="87%" height="52" colspan="2" bgcolor="#009999"> <strong><em><font size="6" face="Tahoma"><!-- InstanceBeginEditable name="EditRegion4" --><font color="#FFFFFF">OmniaSoft
            WEB Business Office</font><!-- InstanceEndEditable --></font></em></strong></td>
  </tr>
  <tr>
    <td height="5%" colspan="2" bgcolor="#009999"><div align="right"><font color="#FFFFFF" size="1" face="Verdana">CopyRight
        (C) </font><font color="#FFFFFF" size="1" face="Verdana"> 2003 OmniaSoft
        by <a href="mailto:prosoft@verat.net">djdejan</a></font></div></td>
  </tr>
  <tr>
    <td height="80%" valign="top" bgcolor="#000000"><div align="center">
        <p><font color="#FFCC00" size="2" face="Tahoma"><strong> <font face="verdana">
          <font face="Tahoma">
          <?php
// Stampanje podataka o korisniku
while (!$upit_izvrsi->EOF)
{
$id=$upit_izvrsi->fields["RecordID"]->value;
?>
          </font><font color="#FFCC00" size="2" face="Tahoma"><strong><font face="verdana"><font face="Tahoma"><img src=includes/user_picture.php?id=<?php echo $id; ?> width="110" height="130"></font></font></strong></font><font face="Tahoma">
          <?php
echo $upit_izvrsi->fields["PreUsr"]->value. '  ' .$upit_izvrsi->fields["ImeUsr"]->value;
?>
          </font></font></strong> </font> <br>
          <font face="verdana"><font color="#FFFFFF" size="2" face="tahoma">Zadnji
          izlaz</font></font><font color="#FFFFFF" size="2" face="tahoma">:</font><font size="2" face="tahoma"><br>
          <strong><font color="#FFFFFF">
          <?php
echo date("d.m.Y H:i", $upit_izvrsi->fields["ZadIzl"]->value);
?>
          </font></strong><br>
          <font color="#FFFFFF">Zadnji ulaz:</font><br>
          <font color="#FFFFFF"><strong>
          <?php
echo date("d.m.Y H:i", $upit_izvrsi->fields["ZadUla"]->value);
?>
          </strong></font></font> <font size="2" face="tahoma"> <br>
          <font color="#FFFFFF">Sadašnji ulaz:</font><br>
          <font color="#FFFFFF"> <strong>
          <?php
echo date("d.m.Y H:i", $upit_izvrsi->fields["SadUla"]->value);
?>
          </strong></font></font></p>
        <p><font size="2" face="tahoma"><font color="#FFFFFF"><strong>
          <?php number_counter($upit_izvrsi->fields["UsrCnt"]->value); ?>
          <br>
          </strong></font><font size="2" face="tahoma"><font color="#FFFFFF"><strong>
          </strong></font></font><font color="#FFFFFF"><strong> <br>
          <?php
$upit_izvrsi->movenext();
}

?>
          </strong></font></font></p>
      </div></td>
    <td height="85%" colspan="2" rowspan="2" valign="top" class="login"> <!-- InstanceBeginEditable name="EditRegion1" -->EditRegion1<!-- InstanceEndEditable --></td>
  </tr>
  <tr>
    <td height="25" valign="bottom" bgcolor="#000000"><div align="left"><a href="logoff.php"><img src="images/cmdLogOff.gif" width="65" height="25" border="0"></a></div></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>



PAGE LOGIN.PHP
------------------

<?php
include("includes/funkcije.php");                     
if(!empty($action))
{
switch($action)
{
case 'login':
login($form_korisnik, $form_server, $form_baza);
break;
}
}
?>
<html>
<head>
<title>Prijava na OmniaSoft WEB Business System</title>

<style type="text/css">
<!--
.login {
   background-repeat: repeat-x;
   background-image:   url('images/loginbg.jpg');
   background-position-y:50%
}
html{
   margin: 0;
   border: 0px none;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250"></head>

<body leftmargin="0" topmargin="0" onLoad="document.login_form.form_server.focus();">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" id="tabela">
  <tr>
    <td valign="top" class="login">
    <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
        <tr>
          <td width="13%" rowspan="3" valign="top" bgcolor="#000000"><div align="center"><font color="#FFFFFF" size="4" face="Tahoma"><strong><?php echo date("d.m.Y.");  ?></strong></font></div></td>
          <td width="87%" height="39" valign="middle" nowrap bgcolor="#009999"> <strong><em><font color="#FFFFFF" size="5" face="Tahoma">
            </font> <font color="#FFFFFF" size="6" face="Tahoma"><img src="images/kljuc.gif" width="92" height="80" align="middle">OmniaSoft
            WEB Business Office</font></em></strong></td>
        </tr>
        <tr>
          <td valign="top">
          <table width="389" border="0" cellspacing="0" cellpadding="0" height="166">
              <tr>
                <td width="52%" height="143"><form action="<?php echo $PHP_SELF; ?>?action=login" method="post" name="login_form" id="login_form">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td width="30" rowspan="9">&nbsp;</td>
                        <td colspan="2"> </td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td width="55"><div align="right"><font size="2" face="Verdana">Server:</font></div></td>
                        <td width="157">
                        <input name="form_server" type="text" id="form_server" style="border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1"  onFocus="this.select();document.all.statusmsg.innerText='Unesite IP adresu servera.'"  <?php if(isset($server_cookie)) { echo ' value="'.$server_cookie.' " size="20" ' ; }?>></td>
                      </tr>
                      <tr>
                        <td><div align="right"><font size="2" face="Verdana">Baza:</font></div></td>
                        <td><input name="form_baza" type="text" id="form_baza" style="border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1" size="20"  onFocus="this.select();document.all.statusmsg.innerText='Unesite naziv baze.'" <?php if(isset($baza_cookie)) { echo ' value="'.$baza_cookie.' " size="20" ' ; }?>></td>
                      </tr>
                      <tr>
                        <td><div align="right"><font size="2" face="Verdana">Korisnik:</font></div></td>
                        <td><input name="form_korisnik" type="text" id="form_korisnik" style="border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1" size="20"  onFocus="this.select();document.all.statusmsg.innerText='Unesite šifru korisnika.'" <?php if(isset($korisnik_cookie)) { echo ' value="'.$korisnik_cookie.' " size="20" ' ; }?>></td>
                      </tr>
                      <tr>
                        <td><div align="right"><font size="2" face="Verdana">Lozinka:</font></div></td>
                        <td><input name="form_lozinka" type="text" id="form_lozinka" style="border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1" size="20" onFocus="this.select();document.all.statusmsg.innerText='Unesite lozinku.' "></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td><input border="0" src="images/prijava.gif" name="I1" width="75" height="25" type="image" size="20"></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp; </td>
                      </tr>
                    </table>
                  </form></td>
                <td width="48%" valign="bottom" height="143"><div align="right">
                  <span style="position: absolute; left: 243px; top: 154px; width: 293px; height: 80px;"><img src="images/LoginSplash_transparent_1.gif" width="220" height="80"></span></div></td>
              </tr>
              <tr>
                <td colspan="2"><div align="right"> <span style="position: absolute; left: 167px; top: 233px; z-index: 1; width: 369px; height: 180px;"><img src="images/LoginSplash_transparent_2.gif" width="300" height="180"></span></div></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td height="20" bgcolor="#F0F0E1">
          <table width="100%" border="0" cellspacing="0" cellpadding="0" height="1">
              <tr>
                <td width="1%" height="1"><font size="2" face="Verdana">&nbsp;</font></td>
                <td width="56%" valign="middle" height="1"><font face="Verdana" size="2">
                  <p id=statusmsg></p>
                  </font></td>
                <td width="43%" height="1"> <font size="1">
                  <?php
//Stampa Error Message
if(!empty($errormessage))
{
print($errormessage);
}
?>
                  </font></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>




When I type http://localhost/, I receive message:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

When I refresh, page is load.
What is wrong?
PLEASE HELP!
djdejan
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Mar 24, 2003 8:31 am

Postby Redcircle » Fri Sep 05, 2003 4:00 pm

IIS Yuck. :)

I'm guessing register globals is probably turned off.

Are you able to get other PHP scripts to work?
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby djdejan » Sat Sep 06, 2003 1:51 am

register_globals is turned ON.
Other scripts work fine.
I found that problem is in header() function, but I don't know how to fix it!
djdejan
New php-forum User
New php-forum User
 
Posts: 7
Joined: Mon Mar 24, 2003 8:31 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 6 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.