Find Jobs
Hire Freelancers

Improving the design of some php code

$10-30 USD

Completato
Pubblicato più di 8 anni fa

$10-30 USD

Pagato al completamento
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.
Rif. progetto: 8561739

Info sul progetto

10 proposte
Progetto a distanza
Attivo 9 anni fa

Hai voglia di guadagnare un po'?

I vantaggi delle offerte su Freelancer

Imposta il tuo budget e le scadenze
Fatti pagare per il lavoro svolto
Delinea la tua proposta
La registrazione e le offerte sui lavori sono gratuite
Assegnato a:
Avatar dell'utente
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 giorno
1,0 (1 valutazione)
1,3
1,3
10 freelance hanno fatto un'offerta media di $24 USD
Avatar dell'utente
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 giorno
4,8 (14 valutazioni)
5,7
5,7
Avatar dell'utente
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 giorno
5,0 (8 valutazioni)
2,8
2,8
Avatar dell'utente
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 giorno
5,0 (5 valutazioni)
2,8
2,8
Avatar dell'utente
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 giorno
5,0 (3 valutazioni)
2,0
2,0
Avatar dell'utente
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 giorno
0,0 (0 valutazioni)
0,0
0,0
Avatar dell'utente
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 giorni
0,0 (0 valutazioni)
0,0
0,0
Avatar dell'utente
A proposal has not yet been provided
$23 USD in 1 giorno
0,0 (0 valutazioni)
0,0
0,0

Info sul cliente

Bandiera: UNITED STATES
Chicago, United States
5,0
8
Metodo di pagamento verificato
Membro dal feb 2, 2015

Verifica del cliente

Grazie! Ti abbiamo inviato tramite email il link per richiedere il tuo bonus gratuito.
Non è stato possibile inviarti l'email. Riprova per piacere.
di utenti registrati di lavori pubblicati
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Caricamento anteprima
Autorizzazione per la geolocalizzazione concessa.
La tua sessione è scaduta ed è stato effettuato il log out. Accedi nuovamente per piacere.