Asked  7 Months ago    Answers:  5   Viewed   37 times

When I use

<form method="post" enctype="text/plain" action="proc.php"> 

form data can not be sent to proc.php file properly. Why? What is the problem? Why I can't use text/plain encoding with post but I can use it with get method?

 Answers

15

[Revised]

The answer is, because PHP doesn't handle it (and it is not a bug):

https://bugs.php.net/bug.php?id=33741

Valid values for enctype in <form> tag are:

application/x-www-form-urlencoded
multipart/form-data

The first is the default, the second one you need only when you upload files.

@Alohci provided explanation why PHP doesn't populate $_POST array, but store the value inside a variable $HTTP_RAW_POST_DATA.

Example of what can go wrong with text/plain enctype:

file1.php:

<form method="post" enctype="text/plain" action="file2.php">
<textarea name="input1">abc
input2=def</textarea>
<input name="input2" value="ghi" />
<input type="submit">
</form>

file2.php:

<?php
print($HTTP_RAW_POST_DATA);
?>

Result:

input1=abc
input2=def
input2=ghi

No way to distinguish what is the value of input1 and input2 variables. It can be

  • input1=abcrninput2=def, input2=ghi, as well as
  • input1=abc, input2=defrninput2=ghi

No such problem when using the other two encodings mentioned before.

The difference between GET and POST:

  • in GET, the variables are part of URL and are present in URL as query string, therefore they must be URL-encoded (and they are, even if you write enctype="text/plain" - it just gets ignored by the browser; you can test it using Wireshark to sniff the request packets),
  • when sending POST, the variables are not part of URL, but are sent as the last header in HTTP request (POSTDATA), and you can choose whether you want to send them as text/plain or application/x-www-form-urlencoded, but the second one is the only non-ambiguous solution.
Wednesday, March 31, 2021
 
rypskar
answered 7 Months ago
77
<?php

 $Input = $_POST['element'];

 $FileToUpdate = "home.php";
 $fh = fopen($FileToUpdate , 'w') or die("can't open file");

 fwrite($fh, $Input);

 fclose($fh);     

 ?>

The code above will do what you wish, but will overwrite the page (to append see this reference). But really I think you need to start from basics with a good PHP Tutorial.

Wednesday, March 31, 2021
 
JohnnyW
answered 7 Months ago
42

One way to solve this is to reinforce your intentions by expliciting formmethod="post", like this:

<button type="submit" formmethod="post" formaction="add_user.php">Submit</button>
Friday, July 30, 2021
 
Revent
answered 3 Months ago
75

Following this guid helped me:

https://docs.microsoft.com/sv-se/xamarin/android/app-fundamentals/notifications/local-notifications-walkthrough

I think the reason I didn't see any notifications was that I didn't have an icon. After adding an icon to the notification, everything worked.

Result:

[Service(Exported = false), IntentFilter(new[] { "com.google.android.c2dm.intent.RECEIVE" })]
public class GcmNotificationService : GcmListenerService
{
    //More information on how to set different things from notification can be found here
    //https://docs.microsoft.com/sv-se/xamarin/android/app-fundamentals/notifications/local-notifications

    public override void OnMessageReceived(string from, Bundle data)
    {
        var message = data.GetString("message");
        if (!string.IsNullOrEmpty(message))
        {
            if (!NotificationContextHelper.Handle(message))
                SendNotification(message);
        }
    }

    private void SendNotification(string message)
    {
        var builder = new Notification.Builder(this)
                .SetContentTitle("Title")
                .SetContentText(message)
                .SetSmallIcon(Resource.Drawable.notification_test)
                .SetVisibility(NotificationVisibility.Public);

        var notification = builder.Build();
        var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
        notificationManager.Notify(0, notification);
    }
}
Saturday, July 31, 2021
 
CKing
answered 3 Months ago
66

Device tokens are not exactly unique per device; they're unique per operating system installation. So if a user buys a new device but does not restore from backup, then they'll get a new device token. And if a device is wiped, it will get a new device token, so the new user doesn't get the old user's messages.

In addition, there are different tokens returned for development apps using the sandbox and distribution apps using the production system.

Since a single user might have your app installed on multiple devices legally (iPhone and iPad, for instance), it will be much safer to have a many to many relationship between users and device tokens, to be on the safe side.

And since you mentioned Urban Airship, you might find that our alias feature helps for this sort of thing; you can assign a non-unique alias to the different tokens in our end, and then we'll keep track of the mapping between your users and their device tokens. See the registration and push parts of the UA documentation.

Edit: An update because I saw some more upvotes on this old answer. As of iOS 7, device tokens are unique for each application, even on the same device.

Monday, August 2, 2021
 
Wilk
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :