简体   繁体   中英

PHP Login form doesn't redirect to another page

validation process works well but it won't redirect to the new "profile.php " page. Pls let me know where I am going wrong.

Here is the html form.

<form name = "fomu_kuingia" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method = "POST">

        <br><br> Barua pepe: <input type="text" name="baruapepe"  />
          <span class = "error" style = "color: #DC143C;"> <?php echo $tatizo;  ?></span>  

        <br><br> Neno la siri:  <input type="password" name="nenosiri" />
         <span class = "error" style = "color: #DC143C;"> <?php echo $tatizo1;  ?></span>

         <br><br><input type="button" value="Nimesahau" name="nimesahau" /><input type="submit" value="Ingia " name="ingia "  />
          <span class = "error" style = "color: #DC143C;"> <?php //echo $jinaErr; ?></span>


        </form>

here is the php function to take data (email/ passed)

 <?php
           //$pepe = " ";
          // $siri = " ";



           function take_data()
        {    $pepe = "";
             $siri = "";

           if ($_SERVER["REQUEST_METHOD"] == "POST")
           {
               if (empty ($_POST["baruapepe"])||empty ($_POST["nenosiri"]))
                {  echo "<font color = '#DC143C' > TATIZO: Tafadhali ingiza barua pepe au neno siri </font>" ;  }


                else {  $pepe = verify($_POST["baruapepe"]);
                        $siri = verify($_POST["nenosiri"]);

                        kuingia ($pepe, $siri); }
           }
         }

           ?>

here if the function to verify data ;php function;

 <?php
           //$pepe = " ";
          // $siri = " ";

           function verify ($data)
           {
               $data = trim ($data);
               $data = stripslashes($data);
               $data = htmlspecialchars($data);
               return $data;
           }


           ?>

and fınally ıs the functıon to check logın (email,paswd) detaıls and redırect to new page .

<?php
           //$pepe = " ";
          // $siri = " ";


           function kuingia ($pp, $sr)
           {
               $con = mysql_connect('localhost', 'root', 'root');

               if (!$con)
               { echo "Connection was not possible ";}

               else 
               {
                   mysql_select_db('DalaliOnline', mysql_connect('localhost', 'root', 'root'));
                   $result = mysql_query("select jina1, jina2 from watumiaji where barua_pepe = '$pp' and neno_siri = '$sr' ");

                   if (!$result)
                   {    echo "Tatizo la mysql"; }

                   else if  (mysql_num_rows($result)== 0)
                   {    echo "<font color = '#DC143C' > TATIZO: Barua pepe au neno siri vimekosewa </font>" ;   }

                   else 
                   { header ("Location:profile.php");
                       echo "umefanikiwa kuingia"; }
               }
           }



           ?>

Your header() call is sending a relative path for the Location header.

According to the PHP documentation for header() , the HTTP/1.1 spec requires an absolute URL:

HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself

It looks like you are also missing a space between the colon ( : ) and the content of the header.

Another common gotcha (although I'm not seeing it in your code above) is that you can't call header() if you've already sent any output to the browser.

The header location should be an absolute url, and there should be a space between Location: and the url, ie;

header ("Location: http://yoursite.com/profile.php");

Also make sure there is nothing outputted to the browser before that header is sent.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM