1

Hi I'm creating a login/registration and the database communication is fine already (data get's stored and loaded as intended). I used Adobe Muse to design the login page and used the form widget to create inputs. On the page "login.html" i have the following form:

<form class="form-grp clearfix mse_pre_init" id="widgetu63897" method="post" enctype="multipart/form-data" action="login_script.php">

  <div class="fld-grp clearfix grpelem" id="widgetu63910" data-required="true"><!-- none box -->
     <span class="fld-input NoWrap actAsDiv rounded-corners clearfix grpelem" id="u63913-4"><!-- content --><input class="wrapped-input" type="email" spellcheck="false" id="widgetu63910_input" name="email" tabindex="1"/><label class="wrapped-input fld-prompt" id="widgetu63910_prompt" for="widgetu63910_input"><span class="actAsPara">E-Mail or username</span></label></span>
  </div>

  <div class="fld-grp clearfix grpelem" id="widgetu63900" data-required="true" data-type="email"><!-- none box -->
    <span class="fld-input NoWrap actAsDiv rounded-corners clearfix grpelem" id="u63901-4"><!-- content --><input class="wrapped-input" type="password" spellcheck="false" id="widgetu63900_input" name="password" tabindex="2"/><label class="wrapped-input fld-prompt" id="widgetu63900_prompt" for="widgetu63900_input"><span class="actAsPara">Password</span></label></span>
  </div>

  <button class="submit-btn NoWrap rounded-corners clearfix grpelem" id="u63909-4" data-muse-uid="U63909" data-muse-type="txt_frame" type="submit" value="Login" tabindex="3"><!-- content -->
   <div style="margin-top:-12px;height:12px;">
    <p>Login</p>
   </div>
  </button>    
</form>

So to test if the login_script.php gets executed I let it send an email to myself which worked. However, if I want to redirect from login_script.php it doesn't work. I have deleted all the code from login_script.php exept for the redirections.

I've tried using

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   echo "<script type='text/javascript'>window.location.href = 'index.html';
}
?>

As well as

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   header('location:index.html');
}
?>

I have no clue what else I could try to fix this issue

  • We need to know where abouts in your script you ran the `header()` function. Remember that `header()` send a header to the browser, and ALL headers must be sent BEFORE anything else is sent to the browser or it will be ignored. So if your `header('location:index.html');` is coded after yoru HTML it wont do anything – RiggsFolly Mar 08 '18 at 10:39
  • You also may need to change `header('location:index.html');` to `header('Location: index.html');` Note the uppercase `L` in location – RiggsFolly Mar 08 '18 at 10:42
  • For your first method, your `echo` is wrong! change it to `echo ""` – Hamza Abdaoui Mar 08 '18 at 10:43
  • Hmm ... can you dump the content of $_SERVER variable. It may be that for some reason the condition `$_SERVER['REQUEST_METHOD'] == 'POST'` is not true. You can also [check this answer](https://stackoverflow.com/a/12754459) – Petko Kostov Mar 08 '18 at 11:18
  • First of all thanks a lot for your solutionsIt seems that the code generated by Adobe Muse `` is causing the problem. everything works as it should after I removed it. However the design gets all messed up when removing it (e.g. the grayed out hints in the input fields don't disappear anymore and the form is off center) I am new to Javascript so if anyone has an idea how to fix this I would highly appreciate it. – user3099337 Mar 09 '18 at 13:32

3 Answers3

0

Hi Try this if the problem still persists kindly comment

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   header('Location:http://google.co.in');
}
?>
Nitish Jha
  • 1
  • 1
  • 3
0
function redirect($url)
{
    if (strpos($url, '://') === false)
    {
        // Make URL absolute
        $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/' . $url;
    }

    if (headers_sent())
    {
        // Send the redirect statement via JavaScript.
        echo "<script>window.location.replace(\"$url\");</script>\n";
    }
    else
    {
        // Use the more efficient HTTP header for redirection.
        header('Location: ' . $url);
    }

    exit;
}

redirect('index.php');

See also

nibra
  • 3,958
  • 2
  • 20
  • 34
-1

Try to echo in

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

and if it works then Try this.

header('Location: http://www.example.com/');
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
SRK
  • 3,476
  • 1
  • 9
  • 23