Php header is not working on server...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chirag vora
    New Member
    • Apr 2013
    • 5

    Php header is not working on server...

    hello...
    my entire project is working fine.
    but when i uploaded it on host..
    it doesnt work..
    prb arise when i enter correct username and password..
    thenafter i doesn;t get redirected to destined page

    thanks
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    Give us the code please........

    Comment

    • chirag vora
      New Member
      • Apr 2013
      • 5

      #3
      Code:
      
      
      
       <?php
      
       
            error_reporting(0);
            session_start();
            include_once 'oesdb.php';
      
            if(isset($_REQUEST['register']))
            {
                  header('Location: register.php');
            }
            else if($_REQUEST['stdsubmit'])
            {
      
                $result=executeQuery("select *,DECODE(stdpassword,'oespass') as std from student where stdname='".htmlspecialchars($_REQUEST['name'],ENT_QUOTES)."' and stdpassword=ENCODE('".htmlspecialchars($_REQUEST['password'],ENT_QUOTES)."','oespass')");
                if(mysql_num_rows($result)>0)
                {
      
                    $r=mysql_fetch_array($result);
                    if(strcmp(htmlspecialchars_decode($r['std'],ENT_QUOTES),(htmlspecialchars($_REQUEST['password'],ENT_QUOTES)))==0)
                    {
                        $_SESSION['stdname']=htmlspecialchars_decode($r['stdname'],ENT_QUOTES);
                        $_SESSION['stdid']=$r['stdid'];
                        unset($_GLOBALS['message']);
                        header('Location: stdwelcome.php');
                    }else
                {
                    $_GLOBALS['message']="Check Your user name and Password.";
                }
      
                }
                else
                {
                    $_GLOBALS['message']="Check Your user name and Password.";
                }
                closedb();
            }
       ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html>
        <head>
          <title>Welcome To VITeQUIZ Online Portal</title>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
          <link rel="stylesheet" type="text/css" href="oes.css"/>
        </head>
        <body>
            <?php
      
              if($_GLOBALS['message'])
              {
               echo "<div class=\"message\">".$_GLOBALS['message']."</div>";
              }
            ?>
            
            <div id="container">
                  
                      <div class="header">
                      <img style="margin:10px 2px 2px 10px;float:left;" height="80" width="200" src="images/logo.gif" alt="OES"/><h3 class="headtext"> &nbsp;VIT UNIVERSITY </h3><h4 style="color:#ffffff;text-align:center;margin:0 0 5px 5px;"><i>...A place to learn; A chance to grow</i></h4>
                  </div>
           <form id="stdloginform" action="index.php" method="post">
            <div class="menubar">
             
             <ul id="menu">
                          <?php if(isset($_SESSION['stdname'])){
                                header('Location: stdwelcome.php');}else{  
                                
                              ?>
      
                            <!--  <li><input type="submit" value="Register" name="register" class="subbtn" title="Register"/></li>-->
                 
      		  
                              <?php } ?>
      						<li><div class="aclass"><a href="/VEQ/register.php" title="Click here  to Register">Student Register</a></div></li>
      						<li><div class="aclass"><a href="/VEQ/index.php" title="Click here  to Register">Student Login</a></div></li>
      						 <li><div class="aclass"><a href="admin/index.php" title="Click here  to Register">Program Manager Login</a></div></li>
      		   <li><div class="aclass"><a href="tc/index.php" title="Click here  to Register">Faculty Login</a></div></li>
                          </ul>
      					
      
            </div>
            <div class="page">
                    
                    <table cellpadding="30" cellspacing="10">
                    <tr>
                        <td>User Name</td>
                        <td><input type="text" tabindex="1" name="name" value="" size="16" /></td>
      
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td><input type="password" tabindex="2" name="password" value="" size="16" /></td>
                    </tr>
      
                    <tr>
                        <td colspan="2">
                            <input type="submit" tabindex="3" value="Log In" name="stdsubmit" class="subbtn" />
                        </td><td></td>
                    </tr>
                  </table>
      
      
            </div>
             </form>
      <?php
      include('footer.php');
      ?>
                </div>
        </body>
      </html>



      Code:
      <?php
      
      
      
      error_reporting(0);
      session_start();
              if(!isset($_SESSION['stdname'])){
                  $_GLOBALS['message']="Session Timeout.Click here to <a href=\"index.php\">Re-LogIn</a>";
              }
              else if(isset($_REQUEST['logout'])){
                      unset($_SESSION['stdname']);
                  $_GLOBALS['message']="You are Loggged Out Successfully.";
                  header('Location: index.php');
              }
      ?>
      <html>
          <head>
              <title>VEQ-DashBoard</title>
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
              <link rel="stylesheet" type="text/css" href="oes.css"/>
          </head>
          <body>
              <?php
             
              if($_GLOBALS['message']) {
                  echo "<div class=\"message\">".$_GLOBALS['message']."</div>";
              }
              ?>
              <div id="container">
                 <div class="header">
                      <img style="margin:10px 2px 2px 10px;float:left;" height="80" width="200" src="images/logo.gif" alt="OES"/><h3 class="headtext"> &nbsp;VIT UNIVERSITY </h3><h4 style="color:#ffffff;text-align:center;margin:0 0 5px 5px;"><i>...A place to learn; A chance to grow</i></h4>
                  </div>
                  <div class="menubar">
      
                      <form name="stdwelcome" action="stdwelcome.php" method="post">
                          <ul id="menu">
                              <?php if(isset($_SESSION['stdname'])){ ?>
                              <li><input type="submit" value="LogOut" name="logout" class="subbtn" title="Log Out"/></li>
                              <?php } ?>
                          </ul>
                      </form>
                  </div>
                  <div class="stdpage">
                      <?php if(isset($_SESSION['stdname'])){ ?>
      				
      
              
                      <img height="600" width="100%" alt="back" src="images/trans.png" class="btmimg" />
                      <div class="topimg"><BR > <BR > <BR >
                          <p><img height="500" width="600" style="border:none;"  src="images/stdwelcome.jpg" alt="image"  usemap="#oesnav" /></p>
      
                          <map name="oesnav">
                              <area shape="circle" coords="158,118,61" href="viewresult.php" alt="View Results" title="Click to View Results" />
                              <area shape="circle" coords="450,120,70" href="stdtest.php" alt="Take a New Test" title="Take a New Test" />
                              <area shape="circle" coords="300,250,60" href="editprofile.php?edit=edit" alt="Edit Your Profile" title="Click this to Edit Your Profile." />
                              <area shape="circle" coords="150,375,70" href="practicetest.php" alt="Practice Test" title="Click to take a Practice Test" />
                              <area shape="circle" coords="450,375,70" href="resumetest.php" alt="Resume Test" title="Click this to Resume Your Pending Tests." />
                        </map>
                      </div>
                      <?php }?>
      
                  </div>
      
                 <?php
      include('footer.php');
      ?>
            </div>
        </body>
      </html>

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        In your first code, i can see lots of new line has been printed at the beginning of the code. This new line is data for php

        If you have already sent data then you cannot redirect using header function. If your warning was enabled you would get an warning, such as header is already sent, or something like that.

        So, remove all the unnecessary white space and characters make sure your first character is <? and do not print any data unless all the verification is finished

        Comment

        • chirag vora
          New Member
          • Apr 2013
          • 5

          #5
          I removed all unnecessary whitespace and characters..
          but still its not working..
          its because of i cant implement your second paragraph ..
          can u please tell me what to do exactly..
          Thanks
          Last edited by Rabbit; Apr 20 '13, 12:24 AM. Reason: Email removed per forum policy

          Comment

          • johny10151981
            Top Contributor
            • Jan 2010
            • 1059

            #6
            on first code on line 70, there is a header function called but before that you printed html code, so this function wont work.

            Comment

            • chirag vora
              New Member
              • Apr 2013
              • 5

              #7
              So now exactly what to do?? How can i write that code before html code?

              Comment

              • johny10151981
                Top Contributor
                • Jan 2010
                • 1059

                #8
                try this
                Code:
                <?php
                      error_reporting(0);
                      session_start();
                      include_once 'oesdb.php';
                 
                      if(isset($_REQUEST['register']))
                      {
                            header('Location: register.php');
                      }
                      else if($_REQUEST['stdsubmit'])
                      {
                 
                          $result=executeQuery("select *,DECODE(stdpassword,'oespass') as std from student where stdname='".htmlspecialchars($_REQUEST['name'],ENT_QUOTES)."' and stdpassword=ENCODE('".htmlspecialchars($_REQUEST['password'],ENT_QUOTES)."','oespass')");
                          if(mysql_num_rows($result)>0)
                          {
                 
                              $r=mysql_fetch_array($result);
                              if(strcmp(htmlspecialchars_decode($r['std'],ENT_QUOTES),(htmlspecialchars($_REQUEST['password'],ENT_QUOTES)))==0)
                              {
                                  $_SESSION['stdname']=htmlspecialchars_decode($r['stdname'],ENT_QUOTES);
                                  $_SESSION['stdid']=$r['stdid'];
                                  unset($_GLOBALS['message']);
                                  header('Location: stdwelcome.php');
                              }else
                          {
                              $_GLOBALS['message']="Check Your user name and Password.";
                          }
                 
                          }
                          else
                          {
                              $_GLOBALS['message']="Check Your user name and Password.";
                          }
                          closedb();
                      }
                	  if(isset($_SESSION['stdname'])){
                                          header('Location: stdwelcome.php');
                						  exit;
                						  }
                 ?>
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                <html>
                  <head>
                    <title>Welcome To VITeQUIZ Online Portal</title>
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
                    <link rel="stylesheet" type="text/css" href="oes.css"/>
                  </head>
                  <body>
                      <?php
                 
                        if($_GLOBALS['message'])
                        {
                         echo "<div class=\"message\">".$_GLOBALS['message']."</div>";
                        }
                      ?>
                 
                      <div id="container">
                 
                                <div class="header">
                                <img style="margin:10px 2px 2px 10px;float:left;" height="80" width="200" src="images/logo.gif" alt="OES"/><h3 class="headtext"> &nbsp;VIT UNIVERSITY </h3><h4 style="color:#ffffff;text-align:center;margin:0 0 5px 5px;"><i>...A place to learn; A chance to grow</i></h4>
                            </div>
                     <form id="stdloginform" action="index.php" method="post">
                      <div class="menubar">
                 
                       <ul id="menu">
                 
                                      <!--  <li><input type="submit" value="Register" name="register" class="subbtn" title="Register"/></li>-->
                                        <li><div class="aclass"><a href="/VEQ/register.php" title="Click here  to Register">Student Register</a></div></li>
                                        <li><div class="aclass"><a href="/VEQ/index.php" title="Click here  to Register">Student Login</a></div></li>
                                         <li><div class="aclass"><a href="admin/index.php" title="Click here  to Register">Program Manager Login</a></div></li>
                           <li><div class="aclass"><a href="tc/index.php" title="Click here  to Register">Faculty Login</a></div></li>
                                    </ul>
                 
                 
                      </div>
                      <div class="page">
                 
                              <table cellpadding="30" cellspacing="10">
                              <tr>
                                  <td>User Name</td>
                                  <td><input type="text" tabindex="1" name="name" value="" size="16" /></td>
                 
                              </tr>
                              <tr>
                                  <td>Password</td>
                                  <td><input type="password" tabindex="2" name="password" value="" size="16" /></td>
                              </tr>
                 
                              <tr>
                                  <td colspan="2">
                                      <input type="submit" tabindex="3" value="Log In" name="stdsubmit" class="subbtn" />
                                  </td><td></td>
                              </tr>
                            </table>
                 
                 
                      </div>
                       </form>
                <?php
                include('footer.php');
                ?>
                          </div>
                  </body>
                </html>

                Comment

                • chirag vora
                  New Member
                  • Apr 2013
                  • 5

                  #9
                  Thanks...but it displays a blank page

                  Comment

                  • Bernybon
                    New Member
                    • May 2009
                    • 1

                    #10
                    Originally posted by chirag vora
                    Thanks...but it displays a blank page
                    Did you find a solution? It's doing the same thing for me!

                    Comment

                    Working...