Editing Script Via Text Field

Ask about a PHP problem here.
Post Reply
Scotty1207
Posts: 7
Joined: Wed Apr 11, 2012 5:45 pm

Editing Script Via Text Field

Post by Scotty1207 »

Hi,

I'm currently I have a script which once a user pays via paypal the name which they put in the box will be used in the script. Below is part of the script:

[syntax=php] $playername = "thenameoftheplayer";[/syntax]

So a user will come to a page it will have a text field and a button and they will type their name into the text field and click pay now. Then PayPal's IPN verifies it and then the script is called up. But I don't know how to make it so that the name which they type in a form text field will be used instead of "thenameoftheplayer" for just that one time.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Editing Script Via Text Field

Post by jacek »

Editing the script itself is a pretty risky strategy, you would be better of using a separate file or database to store the name.

For the file method it's pretty simple

To load the name you can do

[syntax=php]$playername = file_get_contents('last_payment.dat');[/syntax]
and to save it

[syntax=php]file_put_contents('last_payment.dat', 'thenameoftheplayer');[/syntax]
Make sense ? :D
Image
Scotty1207
Posts: 7
Joined: Wed Apr 11, 2012 5:45 pm

Re: Editing Script Via Text Field

Post by Scotty1207 »

So how would I impliment this into a form, my form code is below

Form:
[syntax=text]<form class="well" form action="Scripts/IronDonator" method="post">
<label>Minecraft Player Name</label>
<input type="text" name="playername" class="span3" placeholder="Type something…">
<button type="submit" class="btn btn-info">Buy Now!</button>
</form>[/syntax]

And I take it the script would look like:
[syntax=php]<?php
$HOST = "123.456.7.891"; //the ip of the bukkit server
$password = "YourPasswordHere.";
$playername = file_get_contents('last_payment.dat');

//Can't touch this:
$sock = socket_create(AF_INET, SOCK_STREAM, 0)
or die("error: could not create socket\n");
$succ = socket_connect($sock, $HOST, 4445)
or die("error: could not connect to host\n");

//Authentification
socket_write($sock, $command = md5($password)."<Password>", strlen($command) + 1)
or die("error: failed to write to socket\n");

//Begin custom code here.
socket_write($sock, $command = "/Command/ExecuteConsoleCommand:changegroupcommand $playername Donor;", strlen($command) + 1)
or die("error: failed to write to socket\n");

socket_write($sock, $command = "/Command/ExecuteConsoleCommand:givekitcommand $playername Donor;", strlen($command) + 1)
or die("error: failed to write to socket\n");

socket_write($sock, $command = "/Command/ExecuteConsoleCommand:givemoneycommand $playername 1000;", strlen($command) + 1)
or die("error: failed to write to socket\n");
?>[/syntax]

Also would this work so user1 came used the form with the username user1 and then user2 came and used it with user2, would it just activate the script accordinly?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Editing Script Via Text Field

Post by jacek »

There is a field you can send to paypal which it will just send right back to your IPN script unmodified, I think it's "other" or somethign like that. Is that what you are trying to do ?

So in your form

[syntax=xhtml]<input type="hidden" name="other" value="<player_name>" />[/syntax]
then in your IP script you can use

[syntax=php]$_POST['other'];[/syntax]
which will have this value.

You may need to check the name of the field, I'm 70% sure it's "other" ;)
Image
Post Reply