php redirection working in chorme but not on firefox

1k Views Asked by At

Below is my php code that caries out the redirection

Code Snippet :-

     echo "<form action='exp_yogesh.php?id=$id' method='post'>";
     echo "<td> <input type='image'  name='putonline' value='$id'  src='images/on_button.png'  no-repeat; border:none;' alt='submit'>  </td> ";
     echo "<td> <input type='image'  name='putoffline' value='$id'  src='images/off_botton.png'  no-repeat; border:none;'  alt='submit'>  </td> ";
     echo "</form>";

Here's the exp_yogesh.php file

<?php
include 'includes/connection.php';
session_start();
$new_id= $_GET['id'];

if (isset($_POST['putonline'])) {
    $query = "UPDATE user SET status= '1' WHERE id= '$new_id'";
    $result = $cid-> query($query);
    if ($result== TRUE) {
        header("Refresh:0.01; url=EidtEmp.php");
        exit;
    } else {
        echo "";
    }


}

if (isset($_POST['putoffline'])) {
    $query = "UPDATE user SET status= '0' WHERE id= '$new_id'";
    $result = $cid-> query($query);
    if ($result== TRUE) {
        header("Refresh:0.01; url=EidtEmp.php");
        exit;
    } else {
        echo "not done";
    }
}
mysqli_close($cid);

?>

The above code works properly when I run it on Google Chrome but doesn't when I do the same on Firefox

3

There are 3 best solutions below

1
On

Try this; it might work.

echo("<meta http-equiv='refresh' content='0';url=EidtEmp.php>");  
3
On

Replace top two lines of exp_yogesh.php page.

<?php
include 'includes/connection.php';
session_start();

With

<?php
ob_start();
session_start();
include 'includes/connection.php';

Change your headers functions to:

header("location:EidtEmp.php");
10
On

have you tried using header('location') function?

example :

<?php
if (isset($_POST['putonline'])) {
    $query = "UPDATE user SET status= '1' WHERE id= '$new_id'";
    $result = $cid-> query($query);
    if ($result== TRUE) {
        header("location:EidEmp.php");
        die();
    } else {
        echo "Failed";
    }


}

?>

Edited :

Maybe Change Your header function with javascript function

i.e

echo "<script>window.location.replace('EidtEmp.php');</script>";

or try to change if (isset($_POST['putonline']))

with

if ($_SERVER['REQUEST_METHOD'] == 'POST' )

because Some browsers do not sent the submit button if you hit enter

UPDATED : Try this if you have two conditions

<?php
    include 'includes/connection.php';
session_start();
$new_id= $_GET['id'];

if ($_SERVER['REQUEST_METHOD'] == 'POST' ){
if (isset($_POST['putonline_x'])) {
    $query = "UPDATE user SET status= '1' WHERE id= '$new_id'";
    $result = $cid-> query($query);
    if ($result== TRUE) {
        header("Refresh:0.01; url=EidtEmp.php");
        exit;
    } else {
        echo "";
    }


}

if (isset($_POST['putoffline_x'])) {
    $query = "UPDATE user SET status= '0' WHERE id= '$new_id'";
    $result = $cid-> query($query);
    if ($result== TRUE) {
        header("Refresh:0.01; url=EidtEmp.php");
        exit;
    } else {
        echo "not done";
    }
}
}
mysqli_close($cid);
?>