Find Jobs
Hire Freelancers

Improving the design of some php code

$10-30 USD

Tamamlandı
İlan edilme: 8 yıldan fazla önce

$10-30 USD

Teslimde ödenir
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.
Proje No: 8561739

Proje hakkında

10 teklif
Uzaktan proje
Son aktiviteden bu yana geçen zaman 9 yıl önce

Biraz para mı kazanmak istiyorsunuz?

Freelancer'da teklif vermenin faydaları

Bütçenizi ve zaman çerçevenizi belirleyin
Çalışmanız için ödeme alın
Teklifinizin ana hatlarını belirleyin
Kaydolmak ve işlere teklif vermek ücretsizdir
Seçilen:
Kullanıcı 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 1 gün içinde
1,0 (1 değerlendirme)
1,3
1,3
10 freelancer bu proje için ortalama $24 USD teklif veriyor
Kullanıcı 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 1 gün içinde
4,8 (14 değerlendirme)
5,7
5,7
Kullanıcı 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 1 gün içinde
5,0 (8 değerlendirme)
2,8
2,8
Kullanıcı 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 1 gün içinde
5,0 (5 değerlendirme)
2,8
2,8
Kullanıcı Avatarı
I have experience in passing multiple variables through PHP and I can complete this for you in less than an hour.
$20 USD 0 gün içinde
5,0 (3 değerlendirme)
2,0
2,0
Kullanıcı 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 1 gün içinde
0,0 (0 değerlendirme)
0,0
0,0
Kullanıcı 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 3 gün içinde
0,0 (0 değerlendirme)
0,0
0,0
Kullanıcı Avatarı
A proposal has not yet been provided
$23 USD 1 gün içinde
0,0 (0 değerlendirme)
0,0
0,0

Müşteri hakkında

   UNITED STATES bayrağı
Chicago, United States
5,0
8
Ödeme yöntemi onaylandı
Şub 2, 2015 tarihinden bu yana üye

Müşteri Doğrulaması

Teşekkürler! Ücretsiz kredinizi talep etmeniz için size bir bağlantı gönderdik.
E-postanız gönderilirken bir şeyler yanlış gitti. Lütfen tekrar deneyin.
Kayıtlı Kullanıcı İlan Edlien Toplam İş
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Ön izleme yükleniyor
Coğrafik konum için izin verildi.
Giriş oturumunuzun süresi doldu ve çıkış yaptınız. Lütfen tekrar giriş yapın.