Beginner Wordpress developer here... I am currently developing a Wordpress site for a device of mine. My idea is to be able to connect to the device which acts as a web server. I should be able to access the site from the local device hosting the site (Raspberry Pi from here on referenced to as the server) as well as from any machine/device connected on the same network as the server (mobile phone/laptop etc from here on referenced to as the client).
Connecting directly on the server to the site works fine connecting with http://localhost/mysite. All links and actions work as expected.
Connecting to the site from a client works partially. I can connect and browse wordpress links like pages etc but the below process does not work:
My plugin creates shortcodes which I can add to any page. all functions of the shortcodes basically calls a php file with the following code:
and then creates an html form on the page using the values it got from the above request. The form contains a submit button and when clicked, the form posts it values to:
The mypostphpfile then takes the form values posted to it, writes it to a database and returns to the original page adding a url parameter of "?success=true". This is done using the following code in the mypostphpfile.php file right at the end after all data has been written:
$success="true"; header('Location: http://localhost/mysite/myoriginalformpage/?success=', $success);
I know exactly what the problem is. The problem is the localhost in my URL's which I have so to speak "hardcoded" which I post to/return to. When performing the post on the server and it posts to the localhost php file which is available on the localhost (in the context of the server). When posting from a client, the post does not work because it is posting to a localhost php file which the client browser is looking for on the client computer and not the server.
It seems to be a URL issue. I'm not very familiar with .htaccess files etc and I don't even know if it will be the solution to my problem. I need to be able to post to the php file where it's URL is relative to the server no matter from which device I am browsing the site. I am very new to Wordpress development and searches on the internet leads to not much which makes kind of sense because I don't even know how to describe the problem in a google search bar (as you can see in the question description :). I would like to prevent hard-coding ip addresses as these can change as well as hostnames as I have read these don't always work (on a raspberry pi at least).
So in a nutshell, is there any way that I can pick up which URL wordpress is running from to enable all clients to finish the process. The URL to the php files should be relative to the server.
Any help on this or pointing me in the right direction will be highly appreciated.