Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ajmueller · Nov 29, 2011 at 01:47 AM · phpwwwform

Help with WWWForm, PHP and permissions...?

Greetings all,

I have searched online and found some info on using PHP/MySQL with Unity (like the Server Side High Scores), and several Google searches don't seem to get me closer to what I'm trying to do. Maybe I'm not quite hitting the right search terms, so I thought I'd ask here. Though I'm new to PHP, I think I have a good grasp on how the PHP scripts work on the server side.

Ultimately, I'm trying to test a proof of concept to incorporate into a project. The goal is to click a button in a web player and have it spawn a new window. The button should send two strings containing a name (e.g. John Doe) and an ID code (e.g. 12345) via a WWWForm using the $_POST command in a PHP script.

The PHP script will take the name and ID code and generate a .xfdf (XML Form Data File) via another script (createXFDF PHP script by Justin Koivisto found here if you are really interested) which combines the XFDF data with an Adobe PDF form that has 3 fields: name, ID code, and date. The date is pulled from the local system and inserted into the form while the other two should be passed as POST data. The final result is a printable certificate of completion.

I am able to spawn a new browswer tab using Application.OpenURL. I attempt to pass the name and ID code from my simple Unity project as WWWForm fields:

 void Start ()
 {
     WWWForm form = new WWWForm();
     form.AddField("userName", userName, System.Text.Encoding.UTF8);
     form.AddField("userID", userID);
     www = new WWW(url, form);
 }

When I click the button in the Unity GUI, I spawn the new browser tab and start a Coroutine that waits for the WWW request:

 <?php
 session_start();
 $name = $_POST['userName']; //"John Doe";
 echo $name;
 $userID = 12345;
 echo $userID;
 $_SESSION['name'] = $name;
 $_SESSION['userID'] = $userID;
 ?>

The code above shows 12345 and the GetPDF button in a the newly created browser tab(replicated below since I don't have a URL to host images handy):

12345

[Get PDF]

NOTE: The $name passed in the $_POST doesn't appear to be coming in.

When I look in the Unity Editor Log, I did find this:


 WWW Ok!: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

Authorization Required

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.


I'm using Unity 3.4.2f3 and The Uniform Server 7.1.15-Orion (to run PHP 5.3.8 and Apache 2.2.21 as a local testing server) running on a Windows 7 Professional 64-bit system.

I have also tried my scripts on a Windows Server 2003 system running IIS 6.0 and PHP 5.3.8 since I originally had issues with permissions but I'm seeing similar results.

I thought it is a permissions issue, but I am an administrator on my system and those PHP scripts are all running on the server side. Also, just for grins, I tried passing the string "John%20Doe" as part of the URL and changed the POST to a GET. This actually echoes the string correctly and therefore correctly completes the XFDF file and resulting certificate.

So, after all that, if you are still reading, I guess the real questions are, can anyone tell me what format the AddField strings are being sent to the PHP script? Or, is the userName field always coming up blank due to the HTTP 401 error? And, why would the GET work but the POST not? Are they not subject to same/similar security constraints?

Sorry for the long post, I wanted to give sufficient background and I hope this is enough to get someone to point me in the best direction. Thanks in advance to any kind soul willing to help me.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ajmueller · Dec 01, 2011 at 04:48 AM 0
Share

Looks like I'm 0 for 2 on UnityAnswers... (sigh) Anybody? Anybody? Bueller...

Well, in the case that my question and follow up may help anyone...

After some more searching, I found that I had uncommented a few lines from the .htaccess file to tighten up security. This seems to be the cause of the 401 Authorization Required.

Since commenting those 4 lines out again, I stopped getting the 401 error and the server returns the HT$$anonymous$$L, but the $_POST command still doesn't seem to accept the data and ultimately reach the certificate.

For the moment, I'm using the GET command, but that's not the solution I want.

Can anyone with experience connecting Unity with PHP point me in the right direction?

$$anonymous$$y next challenge is getting a simple login using Unity->PHP->$$anonymous$$ySQL.

avatar image Statement · Apr 13, 2012 at 04:46 PM 0
Share

Check out the PHP example on the wiki. It was designed to be a complement to the docs for WWWForm.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by rutter · Apr 14, 2012 at 03:23 AM

The error probably means exactly what it says: your webserver is blocking the connection because of some permissions issue. If this is not the intended result, you should double check your webserver's configuration.

You mention you're using Apache. You may want to check httpd.conf or htaccess files that block access to POST requests. You can see some examples referencing user auth settings here, or search around the net a bit. In particular, you'll want to check for directives like LIMIT and require valid-user, and consider making some changes to the requirements and/or limited features. Turning off or tweaking these security settings is not necessarily a good idea unless you're very sure of what you're doing, so be careful.

If that doesn't turn up any results, you should check your server's connection and error logs for any clues.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ajmueller · Jun 20, 2012 at 03:52 PM 0
Share

I haven't logged in here for a while, so I just saw this. The project requirements changed and the need for a login and password was dropped. Thanks for the suggestions.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Read second Line of WWWForm.data 1 Answer

Unity WWWForm causes php script to create new session? 1 Answer

How to format data returned from Mysql? 0 Answers

WWWForm/Communication issue despite having a valid crossdomain.xml 1 Answer

Why isn't this $_POST working properly? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges