-1

I have an application to POST data to my webpage. My webpage should use POSTed data to generate a link with parameters and open it.

My webpage has these PHP codes

if(isset($_POST['name']) && isset($_POST['surname']))
    {
        $name = $_POST['name'];
        $surname = $_POST['surname']; 
        header('Location: http://localhost/smcreader/tktest.php?name=' . $name . '&surname=' . $surname);  
    }

My problem is it won't open generated URL. I replace header with echo and add MessageBox.Show(response_stuff) to my app to show response message. It response normally, STATUS is OK, and the response message is a generated link.

peeebeee
  • 2,273
  • 6
  • 18
  • 24

1 Answers1

0

I think that it isn't the right approach for redirect a page dynamically builded. Have you tried an AJAX function?

index.php

<html>
<head>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
  $("#send").click(function(){
    var name    = $("#name").val();
    var surname = $("#surname").val();
    $.ajax({
      type: "POST",
      url: "GenUrl.php",
      data: "name=" + name + "&surname=" + surname,
      dataType: "text",
      success: function(url)
      {
  if (url != "KO") {   
   window.location = url
  }
  else
  {
   $("#result").html("Check Values");
  }
  
      },
      error: function()
      {
        alert("Error......");
      }
    });
  });
});
</script>
<body>
<form name="modulo">
    <p>Name</p>
    <p><input type="text" name="name" id="name"></p>
    <p>Surname</p>
    <p><input type="text" name="surname" id="surname"></p>
    <input type="button" id="send" value="GO">
</form>
<div id="result"></div>
</body>
</html>

GenUrl.php

<?php
if(!empty($_POST['name']) && !empty($_POST['surname']))
    {
        $name = $_POST['name'];
        $surname = $_POST['surname']; 
        echo  "http://localhost/smcreader/tktest.php?name=" . $name . "&surname=" . $surname;  
    }
else
    {
 echo "KO";
    }
?>
An4Th3mA
  • 39
  • 2