-3

For an example, here we are fetching the PHP post variables like status, firstname etc. using PHP code.

<!DOCTYPE html>
<html>
<body>

<?php
$status=$_POST["status"];
$firstname=$_POST["firstname"];
$amount=$_POST["amount"];
$txnid=$_POST["txnid"];
$pid=$_POST["pId"];
$productinformation=$_POST["productinfo"];


echo "<h3>Thank You, " . $firstname .".Your order status is ". $status .".    </h3>";
echo "<h4>Your transaction id for this transaction is ".$txnid.".</h4>";
echo "<h4>We have received a payment of Rs. " . $amount . ". </h4>";
echo "<h4>Your P Id is " . $pid . "</h4>";

?>
</body>
</html>

How to access these POST variables without using PHP page?

Edit: Thanks all for your response. I am not sure why people are downvoting my question. I have spent lot of time to analyse it myself and finally thought of deciding to ask here.

Please find below some more information.

Suppose there is a payment gateway which is sending some response parameters after the completion of transaction. The response parameters are being sent by a PHP post command to the URL that is already provided to the payment gateway while initiating the transaction. We can capture these response parameters using the above code in PHP. I want to know if there is another way where I can capture these response parameters without using a PHP page.

Vpcymn
  • 1
  • 4
  • This question is far to vague. Are you asking how to capture http post data in jsp? – Steve Jun 21 '16 at 11:16
  • You'll have to explain so much more if you want a good answer. I don't know exactly what you want. But if it's what I'm thinking, you could use hidden fields for example. – Phiter Jun 21 '16 at 11:19
  • **POST** is processed server side only so you can't access it using JS. [How to read the post request parameters using javascript](http://stackoverflow.com/questions/1409013/how-to-read-the-post-request-parameters-using-javascript) – Justinas Jun 21 '16 at 11:36
  • Your question still doesn't make sense. You can replace PHP with any programming language you like (providing you can persuade your server to support it / change servers to one that supports it) … but you appear to have working PHP … so what's the problem? – Quentin Jun 21 '16 at 11:59
  • I don't have PHP installed on my system, I want to read these variables in some other way where I can avoid using PHP. @Quentin My question can be vague or stupid but I want to know any possibility that I can do it. – Vpcymn Jun 21 '16 at 12:09

3 Answers3

0

So the payment-provider is sending data back by posting it to a specific page. The requirements to use this payment-provider obviously contains something of a server with PHP, ASP or things like that.

It is impossible to catch post-data client-side. The client is the one sending it. In this case, your payment-provider acts as your client.

If there is a specific reason for not wanting to use PHP, you can look for another server-sided language. Otherwise, just make sure PHP does the job.

  • Hi, actually my project is totally based on servlets and jsp, I dont have PHP installed or have much knowledge about it. I just want to know if there is a way where I can fetch these response parameters other than PHP. – Vpcymn Jun 21 '16 at 12:16
  • Yes, with another server-sided language. There's nothing on the server? – Johannes Mateboer Jun 21 '16 at 12:18
  • I have to provide a URL to payment gateway where it will redirect me to after the payment is successful. Now, this PHP page is used to obtain the response parameters. How can I use any other S-S language? Actually I am new to this so can I use JAVA anyhow to fetch these? – Vpcymn Jun 21 '16 at 12:22
  • "my project is totally based on servlets and jsp" — So use a servlet. – Quentin Jun 21 '16 at 12:28
  • Thanks, could you please help me in understanding how can I use servlet to capture this? – Vpcymn Jun 21 '16 at 12:30
0

So finally I have used PHP only to pull the response parameters and them sending them on the JSP page through servlet.

I am really thankful for all your support.

But I am really dissapointed also with the way some comments and views have come along the way painting my question as vague and inappropriate.

By definition a question can be anything, a stupid one or on the target. Please avoid answering the question if it's not your cup of tea or you can ask for more information, because not every one here is an expert in how to ask a question in most appropriate way.

Thanks.

Vpcymn
  • 1
  • 4
-1

You can, two approaches.

1) Least secure: Parsing PHP data to JS. Capture PHP received values, in Javascript variables.

 var status = <?php echo $_POST['status']; ?>
 var firstname = <?php echo $_POST['firstname']; ?>

.....for each varaible sent by the server.

This approach is prone to attacks.

2) Modern, recommended: Consuming JSON from an API.

This is the ideal and safest approach. Your server must expose data in JSON or XML data format, and then you can consume it directly in javascript without the need of your view getting involved with PHP scripts.

Generally speaking, all modern frameworks, like Angularjs include methods to consume data exposed this way. If not using a framework, vanilla JS can do the work, decoding JSON or XML and capturing data in variables or arrays, then using even localstorage.

digitai
  • 1,870
  • 2
  • 20
  • 37
  • That's just a massive XSS hole (and won't even work for most data). – Quentin Jun 21 '16 at 12:29
  • There is no scope of data coming as JSON or XML actually – Vpcymn Jun 21 '16 at 12:46
  • So you're tied to the server, and the hack to do, not safe, is to parse PHP data to Javascript as I posted in my answer. No way to get data from the server without any of two ways I posted. – digitai Jun 21 '16 at 13:20