Shahnawaz Siddique
Shahnawaz Siddique

Reputation: 111

PHP header works on localhost but not on server

I have tried all solutions of stackoverflow but not working for me. The page stays at index. But registration header is working. if I manually go to stdwelcome.php, it opens which means login is successful and no problem with database. Same problem is also in stdwelcome.php. When I logout, it stays in the same page and does not go to the index.php. I have also tried absolute path of the page, but the problem exists.

<?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();
}
?>

Upvotes: 0

Views: 340

Answers (2)

kkarayat
kkarayat

Reputation: 392

Try using absolute path in header('Location': 'http://example.com/stdwelcome.php') Replace example.com with your domain

Upvotes: 1

Syed mohamed aladeen
Syed mohamed aladeen

Reputation: 6755

try this in place of your header

<script type="text/javascript">
window.location.assign('your desired location');
</script>

Note:close php before script tag and open php after closing script tag

Upvotes: 2

Related Questions