Pas a variable from WE to php Script

Hi,

I am trying to figure out the best way to pass a variable to a php script. I know I could add the data into the url like
mydomain.org?Name=Rich&Content=Invoice

But I would rather keep the data passed hidden.

If I have a Property of a session like Session.Name = Rich

In php can I read it from the $_SESSION[‘Rich’] variable?

The php stuff I plan to replace uses this a lot, setting a session var in one script and reading it in another.

If there is a way to do this then I could just replace some of the php.

Thanks

Rich

Just had a thought, using $_POST[‘VarName’], how would I do that?

you’ll need to use an HTTPSocket or HTTPSecureSocket and send the data via POST.

There’s a good example here: http://documentation.xojo.com/index.php/HTTPSocket.Post

So no way to pass session variables.

Oh well I can make that work.

I’ll give it a try.

OK Here’s my code:


  Dim d as New Dictionary
  Dim s as New HTTPSocket
  
  d.Value("PName") = "Ricky"
  d.Value("PTitle") = "Greatest Hits"
  
  s.SetFormData(d)
  
  s.Post("../test/test.php")

The page test.php doesn’t load???

What did I do wrong?

The response from the php script will be returned to your httpsocket, not presented to the user. Collect the result and display it in an htmlviewer or something.

I can’t.

This php Script process the data and sends it on to Authorize.net and That then calls a PHP script that Sends an email.

I’m trying to replace the UI but keep all the php logic for now.

Sending mail from a WE app is very simple. Maybe you could carry the email from within your app instead of from the php script ?

The main issue is sending the data to authorize.net to process the credit card.

Not sure how to make the call to Authorize.net.

Right, but ultimately, all those chained php scripts will show some kind of page to the user. That is what is returned to your socket. All the rest of it, the processing by authorize.net and the email, will happen as usual, it’s just that last little response to the user that won’t be shown. You can show it directly to the user or show your own indication of success or failure.

One possible issue with your code is that you’re calling the socket in async mode and it’s immediately going out of scope. If that causes a problem, call it synchronously.

s.Post("…/test/test.php", 20)

Does the returned data come as an HTML page?

And is so how do I display it the the HTMLViewer, set it to the URL property.

I tried this but nothing happens, i don’t even see the alert???

  lsStr = s.Post("../test/test.php", 10)
  ExecuteJavaScript("Alert('" + lsStr + "');")
  txtBusTitle.Text = lsStr
  
  HTMLViewer1.LoadPage(lsStr)

Then the application goes offline.

Back in 2002 I used Authorize net and sent transactions through an HTML form. I adapted that to WE code from the LR as such. A quick test showed a response from authorize that seems to indicate the gateway is still valid, but you may want to verify.

[code] dim Socket as new HTTPSecureSocket
Dim d As New Dictionary

d.Value(“x_Amount”) = “1.00”
d.Value(“x_Description”) = “A one dollar item”
d.Value(“x_Receipt_Link_URL”) = “http://www.yoursite.com/cgi-bin/yourreceiptapp.cgi

Socket.SetFormData(d)

// This service simply returns the post data as the result
Dim result As String
result = Socket.Post(“https://secure.authorize.net/gateway/transact.dll”, 30) // Synchronous

result = DefineEncoding(result, Encodings.UTF8)

MsgBox(result)[/code]

To get the response page on the screen, place a webhtmlviewer on your page and replace the MsgBox by

HTMLViewer1.LoadPage(result)

You have to add all the fields needed for a correct transaction, including merchant login. The yourreceiptapp.cgi is a script that Autorize net will call with the result of the transaction. At the time I used a Perl script but it can perfectly well be a web app.

Thank you, I will investigate this.

Do you have any idea why my code above doesn’t display anything?

It just using php and echos the Post vars to the screen.

1 - Are you sure of the URL you post to ? Do you really have your test.php on the same server as your WE app at …/test/ ? I would tend to prefer an absolute address I can call manually from a browser to make sure.

2 - Not knowing what test.php does, it is difficult to know if it works or not. The code I posted uses the webhtmlviewer in a different way which works perfectly.

Maybe you want to test using the URL given by Xojo in its example for post :

http://httpbin.org/post

I tried it and it responds quite nicely. You can even enter it in a browser and it will naturally tell you that it does not accept get :wink:

Here’s the full url: http://aspe.org/xo/test/test.php

This is all it does:

<?php
session_start(); 


Echo "Put -  SName:" . $_GET['Name'] . " - STitle:" . $_GET['Title'] . "</br>";

Echo "Post - PName:" . $_POST['PName'] . " - PTitle:" . $_POST['PTitle'] . "</br>";

?>

[quote=73420:@Richard Albrecht]I tried this but nothing happens, i don’t even see the alert???

  lsStr = s.Post("../test/test.php", 10)
  ExecuteJavaScript("Alert('" + lsStr + "');")
  txtBusTitle.Text = lsStr
  
  HTMLViewer1.LoadPage(lsStr)

Then the application goes offline.[/quote]
You need to give an absolute URL, not a relative one.

Thanks, I will try that.

Is there any way to have that page open in place of the app?

[quote=73429:@Richard Albrecht]Here’s the full url: http://aspe.org/xo/test/test.php

[/quote]

This is the URL you must put in your post :

lsStr = s.Post("http://aspe.org/xo/test/test.php", 10)

OK It worked as long as I included

  lsStr = DefineEncoding(lsStr, Encodings.UTF8)

Now how can I read the data back and present it in the WE app.

I was thinking a coma delimited string,

But thought maybe there was a better way.

Thanks All!!!