PHP redirection goes wrong












-1















I submit all forms of my website to a specific page page form_submition.php, after processing the form data I redirect to another page index.php?page=some page using header function
but in one of my forms that named main_form I get a wrong redirection



    if(isset($_POST['form1']))
{
// process form data
header('Location: ../index.php?page=some page')
}
if(isset($_POST['form2']))
{
// process form data
header('Location: ../index.php?page=some page')
}

$to=$_GET['to']
if (isset($_POST['main_form']) ) {
// process form data
}
header("Location: ../index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
exit();


but it redirects me to mywebsite.com/folders/form_submitions.php?to=all_p



instead of mywebsite.com/index.php?page=all_p



any ideas?



UPDATE 1



I checked my code a lot, it seems that the header is not redirecting the page at all. the strange thing is that the page at mywebsite.com/index.php?page=all_p gets loaded but the url won't change and the css+js files not loaded because the relative path becomes invalid.



UPDATE 2



Further Checking my code, before submitting the main_form to form_submission.php I open a new window with javascript to print some data. the following is the form:



<form enctype='multipart/form-data' action='./forms/form_submitions.php?to=all_p' onsubmit="return checkfiles('attachfiles')">
.
.
.
<button id="main_form" name="main_form" class="btn btn-primary">Save Changes</button>
</form>


I call the following function when #main_form is clicked:



$("#main_form").on('click', function(event) {
newWin = window.open('printingpage.php?data='+ data);
setTimeout(function () { newWin.print(); }, 500);

});


Here the printing function won't return unless the print preview is closed. I think this creates the problem, because when I remove the newWin.print() function, everything works just fine.
is there any ways to make this printing asynchronous?










share|improve this question

























  • Sounds like you have another redirection somewhere, but there's not enough information for us to tell you that with confidence.

    – Brad
    Nov 22 '18 at 3:26











  • Also, this may just be semantics, I think the W3C spec on the Location header notes that the url passed should be absolute.

    – War10ck
    Nov 22 '18 at 3:28











  • dont use ../ instead write the whole url

    – Har Kal
    Nov 22 '18 at 3:29











  • @Brad I don't have any unknown redirection, all of my redirections are in compound statements except for the one that goes wrong.

    – Nawras
    Nov 22 '18 at 3:43











  • @War10ck Apparently, that's changed recently! It's now possible to use relative Location headers.

    – Brad
    Nov 22 '18 at 3:45
















-1















I submit all forms of my website to a specific page page form_submition.php, after processing the form data I redirect to another page index.php?page=some page using header function
but in one of my forms that named main_form I get a wrong redirection



    if(isset($_POST['form1']))
{
// process form data
header('Location: ../index.php?page=some page')
}
if(isset($_POST['form2']))
{
// process form data
header('Location: ../index.php?page=some page')
}

$to=$_GET['to']
if (isset($_POST['main_form']) ) {
// process form data
}
header("Location: ../index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
exit();


but it redirects me to mywebsite.com/folders/form_submitions.php?to=all_p



instead of mywebsite.com/index.php?page=all_p



any ideas?



UPDATE 1



I checked my code a lot, it seems that the header is not redirecting the page at all. the strange thing is that the page at mywebsite.com/index.php?page=all_p gets loaded but the url won't change and the css+js files not loaded because the relative path becomes invalid.



UPDATE 2



Further Checking my code, before submitting the main_form to form_submission.php I open a new window with javascript to print some data. the following is the form:



<form enctype='multipart/form-data' action='./forms/form_submitions.php?to=all_p' onsubmit="return checkfiles('attachfiles')">
.
.
.
<button id="main_form" name="main_form" class="btn btn-primary">Save Changes</button>
</form>


I call the following function when #main_form is clicked:



$("#main_form").on('click', function(event) {
newWin = window.open('printingpage.php?data='+ data);
setTimeout(function () { newWin.print(); }, 500);

});


Here the printing function won't return unless the print preview is closed. I think this creates the problem, because when I remove the newWin.print() function, everything works just fine.
is there any ways to make this printing asynchronous?










share|improve this question

























  • Sounds like you have another redirection somewhere, but there's not enough information for us to tell you that with confidence.

    – Brad
    Nov 22 '18 at 3:26











  • Also, this may just be semantics, I think the W3C spec on the Location header notes that the url passed should be absolute.

    – War10ck
    Nov 22 '18 at 3:28











  • dont use ../ instead write the whole url

    – Har Kal
    Nov 22 '18 at 3:29











  • @Brad I don't have any unknown redirection, all of my redirections are in compound statements except for the one that goes wrong.

    – Nawras
    Nov 22 '18 at 3:43











  • @War10ck Apparently, that's changed recently! It's now possible to use relative Location headers.

    – Brad
    Nov 22 '18 at 3:45














-1












-1








-1








I submit all forms of my website to a specific page page form_submition.php, after processing the form data I redirect to another page index.php?page=some page using header function
but in one of my forms that named main_form I get a wrong redirection



    if(isset($_POST['form1']))
{
// process form data
header('Location: ../index.php?page=some page')
}
if(isset($_POST['form2']))
{
// process form data
header('Location: ../index.php?page=some page')
}

$to=$_GET['to']
if (isset($_POST['main_form']) ) {
// process form data
}
header("Location: ../index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
exit();


but it redirects me to mywebsite.com/folders/form_submitions.php?to=all_p



instead of mywebsite.com/index.php?page=all_p



any ideas?



UPDATE 1



I checked my code a lot, it seems that the header is not redirecting the page at all. the strange thing is that the page at mywebsite.com/index.php?page=all_p gets loaded but the url won't change and the css+js files not loaded because the relative path becomes invalid.



UPDATE 2



Further Checking my code, before submitting the main_form to form_submission.php I open a new window with javascript to print some data. the following is the form:



<form enctype='multipart/form-data' action='./forms/form_submitions.php?to=all_p' onsubmit="return checkfiles('attachfiles')">
.
.
.
<button id="main_form" name="main_form" class="btn btn-primary">Save Changes</button>
</form>


I call the following function when #main_form is clicked:



$("#main_form").on('click', function(event) {
newWin = window.open('printingpage.php?data='+ data);
setTimeout(function () { newWin.print(); }, 500);

});


Here the printing function won't return unless the print preview is closed. I think this creates the problem, because when I remove the newWin.print() function, everything works just fine.
is there any ways to make this printing asynchronous?










share|improve this question
















I submit all forms of my website to a specific page page form_submition.php, after processing the form data I redirect to another page index.php?page=some page using header function
but in one of my forms that named main_form I get a wrong redirection



    if(isset($_POST['form1']))
{
// process form data
header('Location: ../index.php?page=some page')
}
if(isset($_POST['form2']))
{
// process form data
header('Location: ../index.php?page=some page')
}

$to=$_GET['to']
if (isset($_POST['main_form']) ) {
// process form data
}
header("Location: ../index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
exit();


but it redirects me to mywebsite.com/folders/form_submitions.php?to=all_p



instead of mywebsite.com/index.php?page=all_p



any ideas?



UPDATE 1



I checked my code a lot, it seems that the header is not redirecting the page at all. the strange thing is that the page at mywebsite.com/index.php?page=all_p gets loaded but the url won't change and the css+js files not loaded because the relative path becomes invalid.



UPDATE 2



Further Checking my code, before submitting the main_form to form_submission.php I open a new window with javascript to print some data. the following is the form:



<form enctype='multipart/form-data' action='./forms/form_submitions.php?to=all_p' onsubmit="return checkfiles('attachfiles')">
.
.
.
<button id="main_form" name="main_form" class="btn btn-primary">Save Changes</button>
</form>


I call the following function when #main_form is clicked:



$("#main_form").on('click', function(event) {
newWin = window.open('printingpage.php?data='+ data);
setTimeout(function () { newWin.print(); }, 500);

});


Here the printing function won't return unless the print preview is closed. I think this creates the problem, because when I remove the newWin.print() function, everything works just fine.
is there any ways to make this printing asynchronous?







php form-submit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 9:56







Nawras

















asked Nov 22 '18 at 3:23









NawrasNawras

539




539













  • Sounds like you have another redirection somewhere, but there's not enough information for us to tell you that with confidence.

    – Brad
    Nov 22 '18 at 3:26











  • Also, this may just be semantics, I think the W3C spec on the Location header notes that the url passed should be absolute.

    – War10ck
    Nov 22 '18 at 3:28











  • dont use ../ instead write the whole url

    – Har Kal
    Nov 22 '18 at 3:29











  • @Brad I don't have any unknown redirection, all of my redirections are in compound statements except for the one that goes wrong.

    – Nawras
    Nov 22 '18 at 3:43











  • @War10ck Apparently, that's changed recently! It's now possible to use relative Location headers.

    – Brad
    Nov 22 '18 at 3:45



















  • Sounds like you have another redirection somewhere, but there's not enough information for us to tell you that with confidence.

    – Brad
    Nov 22 '18 at 3:26











  • Also, this may just be semantics, I think the W3C spec on the Location header notes that the url passed should be absolute.

    – War10ck
    Nov 22 '18 at 3:28











  • dont use ../ instead write the whole url

    – Har Kal
    Nov 22 '18 at 3:29











  • @Brad I don't have any unknown redirection, all of my redirections are in compound statements except for the one that goes wrong.

    – Nawras
    Nov 22 '18 at 3:43











  • @War10ck Apparently, that's changed recently! It's now possible to use relative Location headers.

    – Brad
    Nov 22 '18 at 3:45

















Sounds like you have another redirection somewhere, but there's not enough information for us to tell you that with confidence.

– Brad
Nov 22 '18 at 3:26





Sounds like you have another redirection somewhere, but there's not enough information for us to tell you that with confidence.

– Brad
Nov 22 '18 at 3:26













Also, this may just be semantics, I think the W3C spec on the Location header notes that the url passed should be absolute.

– War10ck
Nov 22 '18 at 3:28





Also, this may just be semantics, I think the W3C spec on the Location header notes that the url passed should be absolute.

– War10ck
Nov 22 '18 at 3:28













dont use ../ instead write the whole url

– Har Kal
Nov 22 '18 at 3:29





dont use ../ instead write the whole url

– Har Kal
Nov 22 '18 at 3:29













@Brad I don't have any unknown redirection, all of my redirections are in compound statements except for the one that goes wrong.

– Nawras
Nov 22 '18 at 3:43





@Brad I don't have any unknown redirection, all of my redirections are in compound statements except for the one that goes wrong.

– Nawras
Nov 22 '18 at 3:43













@War10ck Apparently, that's changed recently! It's now possible to use relative Location headers.

– Brad
Nov 22 '18 at 3:45





@War10ck Apparently, that's changed recently! It's now possible to use relative Location headers.

– Brad
Nov 22 '18 at 3:45












2 Answers
2






active

oldest

votes


















-1














remove .. parts in your paths & try.



So the code will be :



 if(isset($_POST['form1']))
{
// process form data
header('Location: /index.php?page=some page')
}
if(isset($_POST['form2']))
{
// process form data
header('Location: /index.php?page=some page')
}

$to=$_GET['to']
if (isset($_POST['main_form']) ) {
// process form data
}
header("Location: /index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
exit();





share|improve this answer

































    -1














    Try this. Put your web link in your redirection link.



    header("Location: http://www.mywebsite.com/index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);


    Hope this helps.






    share|improve this answer
























    • Use http_build_query() instead of just concatenating data into a URL.

      – Brad
      Nov 22 '18 at 13:40












    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423415%2fphp-redirection-goes-wrong%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    remove .. parts in your paths & try.



    So the code will be :



     if(isset($_POST['form1']))
    {
    // process form data
    header('Location: /index.php?page=some page')
    }
    if(isset($_POST['form2']))
    {
    // process form data
    header('Location: /index.php?page=some page')
    }

    $to=$_GET['to']
    if (isset($_POST['main_form']) ) {
    // process form data
    }
    header("Location: /index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
    exit();





    share|improve this answer






























      -1














      remove .. parts in your paths & try.



      So the code will be :



       if(isset($_POST['form1']))
      {
      // process form data
      header('Location: /index.php?page=some page')
      }
      if(isset($_POST['form2']))
      {
      // process form data
      header('Location: /index.php?page=some page')
      }

      $to=$_GET['to']
      if (isset($_POST['main_form']) ) {
      // process form data
      }
      header("Location: /index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
      exit();





      share|improve this answer




























        -1












        -1








        -1







        remove .. parts in your paths & try.



        So the code will be :



         if(isset($_POST['form1']))
        {
        // process form data
        header('Location: /index.php?page=some page')
        }
        if(isset($_POST['form2']))
        {
        // process form data
        header('Location: /index.php?page=some page')
        }

        $to=$_GET['to']
        if (isset($_POST['main_form']) ) {
        // process form data
        }
        header("Location: /index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
        exit();





        share|improve this answer















        remove .. parts in your paths & try.



        So the code will be :



         if(isset($_POST['form1']))
        {
        // process form data
        header('Location: /index.php?page=some page')
        }
        if(isset($_POST['form2']))
        {
        // process form data
        header('Location: /index.php?page=some page')
        }

        $to=$_GET['to']
        if (isset($_POST['main_form']) ) {
        // process form data
        }
        header("Location: /index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
        exit();






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 5:13

























        answered Nov 22 '18 at 3:45









        GayanthaGayantha

        9726




        9726

























            -1














            Try this. Put your web link in your redirection link.



            header("Location: http://www.mywebsite.com/index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);


            Hope this helps.






            share|improve this answer
























            • Use http_build_query() instead of just concatenating data into a URL.

              – Brad
              Nov 22 '18 at 13:40
















            -1














            Try this. Put your web link in your redirection link.



            header("Location: http://www.mywebsite.com/index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);


            Hope this helps.






            share|improve this answer
























            • Use http_build_query() instead of just concatenating data into a URL.

              – Brad
              Nov 22 '18 at 13:40














            -1












            -1








            -1







            Try this. Put your web link in your redirection link.



            header("Location: http://www.mywebsite.com/index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);


            Hope this helps.






            share|improve this answer













            Try this. Put your web link in your redirection link.



            header("Location: http://www.mywebsite.com/index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);


            Hope this helps.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 11:02









            Madhur SharmaMadhur Sharma

            1276




            1276













            • Use http_build_query() instead of just concatenating data into a URL.

              – Brad
              Nov 22 '18 at 13:40



















            • Use http_build_query() instead of just concatenating data into a URL.

              – Brad
              Nov 22 '18 at 13:40

















            Use http_build_query() instead of just concatenating data into a URL.

            – Brad
            Nov 22 '18 at 13:40





            Use http_build_query() instead of just concatenating data into a URL.

            – Brad
            Nov 22 '18 at 13:40


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423415%2fphp-redirection-goes-wrong%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents