Home › Forums › General Questions › PHP in Verge3d Development
- This topic has 4 replies, 2 voices, and was last updated 5 years, 1 month ago by Yuri Kovelenov.
-
AuthorPosts
-
2019-11-08 at 2:22 pm #21018CrunchCustomer
I would like to add some PHP to my user interface that mounts my verge app – more specifically i would to be able to test it locally in verge dev enviornment. Is there any way to configure Verge3d app manager to recognize and process PHP?
2019-11-09 at 9:00 am #21025Yuri KovelenovStaffHi,
You can copy your Verge3D application folder (which contains only static files) to the PHP environment (Apache web server folder for static files?) and embed it in a web page with iframe. This way, your 3d app will be loaded in the context of the website, so Puzzles/JavaScript will have the access to any HTML elements provided by PHP. When working with 3d graphics, select the export path to update the gltf file in the PHP folder (no need in the App Manager after you created an app and copied it to a website folder.
2019-11-09 at 9:01 am #21029Yuri KovelenovStaff2019-11-11 at 6:53 pm #21044CrunchCustomerThanks for the tips Yuri. What I ended up doing (so I can test locally) is I changed the configuration file in Xaamp to point to my document root being my Verge applications directory, instead of the default c:/xampp/htdocs folder
Directions I found here: http://www.javadtaghia.com/clam/xampp-linux-windows/howtochangexampplocalhosttoanotherfolderoutsidexamppfolder
I then add some PHP code instead my projectname.html file and rename it with a .php extension. For testing I have xampp running and chrome (via xampp) open pointed at the file I am working on, and have firefox (my default browser for verge3d app) open where I can experiment in puzzles. Then I just tab over to chrome and refresh to quickly view the results.
Seems to be working great so far. The reason I had to get into PHP (and Mysql) in the first place is to be able to make content available only to registered users (via a login and registrations pages)
I wish there was a puzzle and ‘easy’ button for that shit!
My experiments so far show that trying to ‘envoke’ php code (even on via a local server) within puzzles isn’t going to work. I am I correct there?
For now, the code (PHP + mySQL) I am using (more like tweaking as I am not smart enough to write it) to manage logins creates a few Session variables like username and user id. I’d like to be able to access those in puzzles so for example, when a user clicks a 3d cube object,I have some HTML based puzzles that conjure up a modal window that gives a personalized message like “Great job <username>!”
To do that, I need to access the Session variables in puzzles.
Is there an easy way to do this?
So far what I have figured out, is that after the user logins I assign the Session variable value to a hidden html element, like this
<?php echo “<input type=’hidden’ id=’username’ value='”.$_SESSION[‘username’].”‘/>”;?>
Then in puzzles, I use the html get attribute puzzle to get the value of the element with id “username” and assign it to a new variable inside puzzles.
Which works, but is there a better way of doing this? Like any way to capture Session variables via puzzles or custom javascript?
Thanks2019-11-12 at 6:18 am #21047Yuri KovelenovStaffHi,
I think your approach with using a hidden element and HTML puzzles is already good.
Alternatively, you can write your $_SESSION[‘username’] variable to a global JavaScript variable and access it with JavaScript. We did something like this in our WooCommerce integration module.
Another way is to embed some JavaScript in your php page so that it directly calls a procedure puzzle using that $_SESSION[‘username’] variable as argument.
-
AuthorPosts
- You must be logged in to reply to this topic.