Find Jobs
Hire Freelancers

Improving the design of some php code

$10-30 USD

Completed
Posted over 8 years ago

$10-30 USD

Paid on delivery
I have some GEO IP code that directs users from a specific city, as interpreted by their IP address, to a specific URL. Rather than repeating the code below several times, as illustrated below for several cities. I'd like to have the code written in a more efficient way where I can list multiple cities in the argument. The code is in the php section of my wordpress header $geo = WPEngine\GeoIp::instance(); if ( $geo->city() == "New York") { wp_redirect( '[login to view URL]', 301 ); exit; } if ( $geo->city() == "Oak Park") { wp_redirect( '[login to view URL]', 301 ); exit; } As you can see, I have used the "if" statement twice for "New York" and "Oak Park." I'd like to be able to efficiently add 20 or 30 cities in the most efficient manner possible. Thank you.
Project ID: 8561739

About the project

10 proposals
Remote project
Active 9 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
you have multiple solutions for this. 1. switch statement, this still will require additional modification if you add more cities, [login to view URL] arrays and loops, this will allow you to perform essentially the same task for each city but with slightly different information: ie: $c = $geo->city(); foreach($cities as $city => $url){if($city === $c) {header('Location: '.$url)}}... I am not sure that it would really be this simple but my point is this is a relatively simple issue that can be handle with various methods we would have to talk to figure out which is truly the best for your situation... 3. (just throwing another one in) if you use the city name at the key to your array value you can do something like this $c = $geo->city(); $url = $cities[$c]; if($url) {wp_redirect($url);}else{wp_redirect('some fallback url');}exit; On a different note... if you wanted to make this a bit more responsive you could use longitude and latitude which would allow you to redirect any user the closest "supported" city even if there geocode does not reflect that city (this would be very similar to the way craigslist autolocate feature works). and then if location services is off it can fallback to a city selection page. (this is much more extensive, not sure if you need something like that)
$25 USD in 1 day
1.0 (1 review)
1.3
1.3
10 freelancers are bidding on average $24 USD for this job
User Avatar
I think I am a good fit for this job because I have all the qualities that you are looking for. Experience is the golden factor in this project where you find in me at least 3+ years of working experiences over all the factors in your project.
$25 USD in 1 day
4.8 (14 reviews)
5.7
5.7
User Avatar
I can improve this solution for you. Do you have a database in a backgroun where we can put a table which links the cities to states? Or does GeoIp::instance object contain that info? Should be easy task
$25 USD in 1 day
5.0 (8 reviews)
2.8
2.8
User Avatar
We know how to overcome this problem. We already have the design in mind all that is left is for you to contact us.
$20 USD in 1 day
5.0 (5 reviews)
2.8
2.8
User Avatar
I have experience in passing multiple variables through PHP and I can complete this for you in less than an hour.
$20 USD in 0 day
5.0 (3 reviews)
2.0
2.0
User Avatar
I have a keen eye for attention to detail and high affinity to great design. The projects I make are fully functional, gorgeous looking and easily maintainable.
$25 USD in 1 day
0.0 (0 reviews)
0.0
0.0
User Avatar
I have a good expertize in different web developing areas. I can be of some help for you in executing this project.
$25 USD in 3 days
0.0 (0 reviews)
0.0
0.0
User Avatar
A proposal has not yet been provided
$23 USD in 1 day
0.0 (0 reviews)
0.0
0.0

About the client

Flag of UNITED STATES
Chicago, United States
5.0
8
Payment method verified
Member since Feb 2, 2015

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.