Forum Moderators: coopster

Message Too Old, No Replies

What does echo do?

         

lindajames

7:37 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



I have the following PHP Code:

$gi = geoip_open("data.dat",GEOIP_STANDARD);
echo geoip_country_name_by_addr($gi, "62.255.64.5") . "\n";
geoip_close($gi);

Can anyone tell me what the echo line is doing? and as you can see i have specified the IP address, how can i get the code to detect the users IP instead?

Any help would be appreciated.

Cheers
Linda

daisho

7:40 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



echo is like print. It displays the result of geoip_country_name_by_addr() to the screen.

Change "62.255.64.5" to $_SERVER['REMOTE_ADDR'] that will give you the IP address of the client.

daisho.

lindajames

8:30 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



if echo is like print, then how can i redirect the user to a subfolder/response_value instead of printing the response_value?

daisho

8:48 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



switch( geoip_country_name_by_addr($gi, "62.255.64.5") ) {
case "Canada":
break;
case "United States":
break;
default:
break;
}

lindajames

8:50 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



whats the case & break commands for?

Birdman

9:00 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Switch() [php.net] is kind of like doing a series of if-then statements, but alot prettier. Only use switch when you are evaluating one value, as in your current post.

If you want to redirect according to the country, use a header() [php.net] for each case.

Break stops the evaluations when there is a match.

switch( geoip_country_name_by_addr($gi, "62.255.64.5") ) {
case "Canada":
header("path/");
break;
...and so on...
}

lindajames

9:11 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



So for example, say if i wanted to redirect users from Canada to a folder called "canada" and users from uk to a folder called "uk" is this how it will be done:

switch( geoip_country_name_by_addr($gi, "62.255.64.5") ) {
case "Canada":
header("http://mydomain.com/canada");
break;
case "UK":
header("http://mydomain.com/uk");
break;
}

if thats correct then how do i get users that dont meet those case to be redirected to someother folder?

Cheers
Linda

Birdman

10:13 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's what default is for:

default:
header();
break;