2

My Header location not working on live i have Godaddy hosting and my other projects works perfect but on localhost working Perfect.

<?php

    $dataerr    =   "";
    $valueX     =   rand(1, 6);
    $valueY     =   rand(6, 9);
    $bodmas     =   array('+', '-', '*');
    shuffle($bodmas);
    eval("\$ans=".$valueY.$bodmas[0].$valueX.";");
    $security = md5($ans);



    if(isset($_POST['vname']))  {$visname   =   $_POST['vname'];}
    if(isset($_POST['vemail'])) {$visemail  =   $_POST['vemail'];}
    if(isset($_POST['ccode']))  {$ccode     =   $_POST['ccode'];}
    if(isset($_POST['hcode']))  {$hcode     =   $_POST['hcode'];}

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

    $passing    =   md5($ccode);


    if((!filter_var($visemail, FILTER_VALIDATE_EMAIL)) or (!preg_match("/^[a-zA-Z ]*$/",$visname)) or
        (!is_numeric($ccode)) or ($passing !== $hcode)) {

            $displayblock = "showERROR";

            if(!preg_match("/^[a-zA-Z ]*$/",$visname)) {
                $dataerr .= '<span class=""><li>Please enter valid name !</li></span>'; 
            }

            if(!filter_var($visemail, FILTER_VALIDATE_EMAIL)) {
                $dataerr .= '<span class=""><li>Please enter valid email address !</li></span>';
            }

            if(!is_numeric($ccode)){
                $dataerr .= '<span class=""><li>Solve the sum, no kidding !</li></span>';
            } else {if($passing !== $hcode){
                    $dataerr .= '<span class=""><li>Your answer was Incorrent !</li></span>';
                }
            }

        } else {
            session_start();
            $_SESSION['DSTAR'] = "DSTARINFOTECH";
            header('Location: http://www.example.com/');
        }
    } 

    ?>
John Conde
  • 217,595
  • 99
  • 455
  • 496
dhna
  • 71
  • 2
  • 10

6 Answers6

1

Try

 echo "<script>window.location.href='http://www.example.com/';</script>";
pran
  • 29
  • 1
  • 7
  • But this not a right way to solve my problem, i want to know where have the problem in my script – dhna Apr 07 '15 at 08:20
0

try to add exit() after header() may be because of different output buffering settings between servers

header('Location: http://www.example.com/');
exit();
Osama Jetawe
  • 2,697
  • 6
  • 24
  • 40
0

Try to use die(); after header(...);

header('Location: http://www.example.com/');
die();

Look at this: How to make a redirect in PHP?

Community
  • 1
  • 1
oscarvady
  • 450
  • 1
  • 4
  • 12
0

Add the following function on the top of your page on which header() is than try and header() will work for you.

ob_start();
Iffi
  • 608
  • 1
  • 7
  • 16
0

Turn error reporting on.

There's a strong posibility that you're already sending a header, and thus, receiving the Header already sent....

Possible causes for this are:

  • Having a PHP closing tag in the file.
  • Byte order mark - This depends a lot on your editor.
  • session_start() is known to modify headers.
  • Previous errors/warning/etc from PHP.
  • Sending unintentional whitespace before the header.

So once again. Turn error reporting on and carefully check your code.

Check out this question for further and more in-depth information.

Community
  • 1
  • 1
Andrei
  • 3,434
  • 5
  • 21
  • 44
  • Warning: session_start(): Cannot send session cache limiter - headers already sent – dhna Apr 07 '15 at 09:47
  • Well there you go. Put session_start() at the very beginning, and I mean at the very beginning, of the file. Right after the – Andrei Apr 07 '15 at 09:56
0

Am not sure but try this. Add the page where you need to go.

header('Location: index.php');
Bivin
  • 106
  • 1
  • 8