1

why header function does not work here ? it work successfully on localhost

<?php
    session_start();
    if(isset($_POST['submit'])){
        require_once('models/config.php');  require_once('models/mysql.class.php');
        $username=$_POST['username'];
        $password=$_POST['password'];       
        $obj_Pharmacies=new mysql();     
        $sql_query="SELECT * FROM `sellers_accounts` WHERE`user_name`='$username' AND `password`='$password'";
        $obj_Pharmacies->Execute($sql_query);
        if($obj_Pharmacies->Execute($sql_query)){

            $Pharmacies=$obj_Pharmacies->GetRows();         
            $cookie_seller_name=$Pharmacies[0]['name'];         
            $cookie_seller_user_name=$Pharmacies[0]['user_name'];
            $Pharmacies_number=count($Pharmacies);
            if($Pharmacies_number>=1){
                //$_SESSION['sellerName']=$cookie_seller_name;
                setcookie('sellerName', $cookie_seller_name, time() + (86400 * 30), "/");
                //$_SESSION['sellerUsername']=$cookie_seller_user_name;
                //$_SESSION['sellerName'];
                header("location:plans.php");
          }     
        }


    } 
?>
9
  • Have a look at this article set cookie header missing Commented Sep 3, 2016 at 12:13
  • Enable error reporting. Most likely there is a warning (headers already sent ...) and you just don't see it. Commented Sep 3, 2016 at 12:19
  • it works successfully on localhost and my host although when i uploaded the code on my client host it does not work Commented Sep 3, 2016 at 12:20
  • how can i enalble error reporting ? Commented Sep 3, 2016 at 12:23
  • stackoverflow.com/questions/845021/… Commented Sep 3, 2016 at 12:23

1 Answer 1

1
$base_url =  "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
   $redirect_url = $base_url."plans.php";
   header("location:$redirect_url");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.