Welcome Guest, Not a member yet? Register   Sign In
determining the address of the server?
#1

The way my app has been designed is that each server has a copy of wordpress, copy of the application, and a copy of the fusionAuth server. When a user reaches my website, researchStudyOnline.com, the AWS load balancer determines which server will be handling this request by displaying my landing page. My landing page has a button: Login to Research Study Online. This will bring them to my app at a certain URL on that server. 

On my laptop "server" the address of the server is localhost. So to login they get sent to localhost/index.php/Login.
Bur how will this work on my AWS server? Will localhost still be the local server or will I use xx.xx.xx.xx/index.php/Login?
proof that an old dog can learn new tricks
Reply
#2

On live servers localhost is usually used for MySQL servers so you would need to use the full url address.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

There is a problem. Each server (this is designed to handle a few) will have a different address. But the code running on all of them is the same. I'm seeking a CI function that returns the IP of the current server. Then I can use a var called server_address instead of the hard coded address.
proof that an old dog can learn new tricks
Reply
#4

@richb201,

Try experimenting with the following to find the Server parameters. I would also prevent rendering the details unless a certain $_GET value is verified to prevent others from seeing sensitive server information.
PHP Code:
// pre adds line-feeds for easier readability
  
echo '<pre>'print_r$_SERVER ); echo '</pre>';  
Reply
#5

(This post was last modified: 08-25-2021, 04:21 AM by richb201.)

Thx. I tried this:
$IP=$_SERVER[SERVER_ADDR];

$IP is 172.19.0.3

But when I try typing that URL in the browser (on my laptop), I get
This site can’t be reached
proof that an old dog can learn new tricks
Reply
#6

I think the SERVER_ADDR parameter applies to the Internet Service Provider.

Try the REQUEST_URI parameter.
Reply
#7

I tried $IP=$_SERVER[REQUEST_URI];

and this yields
/index.php/Configure/index
proof that an old dog can learn new tricks
Reply
#8

on my local dev I have a web dev thats configured to be served on 127.0.0.2

if i put this code in a controller :

Code:
$IP2=  strval($_SERVER['SERVER_ADDR']);
    echo $IP2;

it correctly returns 127.0.0.2
Reply
#9

(This post was last modified: 08-25-2021, 02:24 PM by John_Betong.)

@rich2b01,
I have a similar app that at the user point of entry tests for the environment URL, defines a constant then requires a common application. The common application uses the defined constant and sets the relevant MySQL database tables, paths, etc.
Reply
#10

He is on AWS and some people have reported problems trying to get the host address see below.

PHP Code:
// From PHP.net - gethostbyaddr()

if the user is sitting behind a proxy serveryou can do this;

if (
$HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"] != "") {
    $IP $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
    $proxy $HTTP_SERVER_VARS["REMOTE_ADDR"];
    $host = @gethostbyaddr($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]);
} else {
    $IP $HTTP_SERVER_VARS["REMOTE_ADDR"];
    $host = @gethostbyaddr($HTTP_SERVER_VARS["REMOTE_ADDR"]);



You should be careful in the use of $_SERVER['HTTP_X_FORWARDED_FOR'], as I discovered,
once using Amazon AWS's Elastic Load Balancer's, this value may be a comma separated list
of IP addresses and will thusly not compare as conceived in almost every example I have
seen posted by users in the comments.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB