Find Jobs
Hire Freelancers

Improving the design of some php code

$10-30 USD

Selesai
Dibuat lebih dari 8 tahun yang lalu

$10-30 USD

Dibayar ketika dikirim
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.
ID Proyek: 8561739

Tentang proyek

10 proposal
Proyek remot
Aktif 9 tahun yang lalu

Ingin menghasilkan uang?

Keuntungan menawar di Freelancer

Tentukan anggaran dan garis waktu Anda
Dapatkan bayaran atas pekerjaan Anda
Uraikan proposal Anda
Gratis mendaftar dan menawar pekerjaan
Diberikan kepada:
Avatar Pengguna
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 dalam 1 hari
1,0 (1 ulasan)
1,3
1,3
10 freelancer menawar dengan rata-rata $24 USD untuk pekerjaan ini
Avatar Pengguna
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 dalam 1 hari
4,8 (14 ulasan)
5,7
5,7
Avatar Pengguna
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 dalam 1 hari
5,0 (8 ulasan)
2,8
2,8
Avatar Pengguna
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 dalam 1 hari
5,0 (5 ulasan)
2,8
2,8
Avatar Pengguna
I have experience in passing multiple variables through PHP and I can complete this for you in less than an hour.
$20 USD dalam 0 hari
5,0 (3 ulasan)
2,0
2,0
Avatar Pengguna
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 dalam 1 hari
0,0 (0 ulasan)
0,0
0,0
Avatar Pengguna
I have a good expertize in different web developing areas. I can be of some help for you in executing this project.
$25 USD dalam 3 hari
0,0 (0 ulasan)
0,0
0,0
Avatar Pengguna
A proposal has not yet been provided
$23 USD dalam 1 hari
0,0 (0 ulasan)
0,0
0,0

Tentang klien

Bendera UNITED STATES
Chicago, United States
5,0
8
Memverifikasi Metode pembayaran
Anggota sejak Feb 2, 2015

Verifikasi Klien

Terima kasih! Kami telah mengirim Anda email untuk mengklaim kredit gratis Anda.
Anda sesuatu yang salah saat mengirimkan Anda email. Silakan coba lagi.
Pengguna Terdaftar Total Pekerjaan Terpasang
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Memuat pratinjau
Izin diberikan untuk Geolokasi.
Sesi login Anda telah kedaluwarsa dan Anda sudah keluar. Silakan login kembali.