Sunday, 15 January 2012

php - Pulling country from array, then using "if/else" to determine if a redirect is needed -



php - Pulling country from array, then using "if/else" to determine if a redirect is needed -

one of classes on our website drops list of countries select when trying order product has many items. 3 countries - russia, republic of belarus , republic of kazakhstan - need separated list , redirect user russian website due registration conflicts , such. used include country code in url entered order page, , there based on countries switch languages. languages irreverent in case. located class responsible list , function proceed order page country indicated. want include "if/else" statement in there, "if person selected ru, or kz = redirect website" or "else = homecoming country code" else seems fine, dreamweaver keeps telling me there issue "if" statement line , tried working around different ways of writing syntax no luck.

<?php class countryutil { public static $country_list = array( 'af' => 'afghanistan', 'ax' => 'aland islands', 'al' => 'albania', 'dz' => 'algeria', 'as' => 'american samoa', 'ad' => 'andorra', 'ao' => 'angola', 'ai' => 'anguilla', 'aq' => 'antarctica', 'ag' => 'antigua , barbuda', 'ar' => 'argentina', 'am' => 'armenia', 'aw' => 'aruba', 'au' => 'australia', 'at' => 'austria', 'az' => 'azerbaijan', 'bs' => 'bahamas', 'bh' => 'bahrain', 'bd' => 'bangladesh', 'bb' => 'barbados', 'by' => 'belarus', 'be' => 'belgium', 'bz' => 'belize', 'bj' => 'benin', 'bm' => 'bermuda', 'bt' => 'bhutan', 'bo' => 'bolivia', 'ba' => 'bosnia , herzegovina', 'bw' => 'botswana', 'bv' => 'bouvet island', 'br' => 'brazil', 'io' => 'british indian ocean territory', 'bn' => 'brunei darussalam', 'bg' => 'bulgaria', 'bf' => 'burkina faso', 'bi' => 'burundi', 'kh' => 'cambodia', 'cm' => 'cameroon', 'ca' => 'canada', 'cv' => 'cape verde', 'ky' => 'cayman islands', 'cf' => 'central african republic', 'td' => 'chad', 'cl' => 'chile', 'cn' => 'china', 'co' => 'colombia', 'km' => 'comoros', 'cg' => 'congo', 'ck' => 'cook islands', 'cr' => 'costa rica', 'ci' => 'cote d\'ivoire', 'hr' => 'croatia', 'cu' => 'cuba', 'cy' => 'cyprus', 'cz' => 'czech republic', 'dk' => 'denmark', 'dj' => 'djibouti', 'dm' => 'dominica', 'do' => 'dominican republic', 'ec' => 'ecuador', 'eg' => 'egypt', 'sv' => 'el salvador', 'gq' => 'equatorial guinea', 'er' => 'eritrea', 'ee' => 'estonia', 'et' => 'ethiopia', 'fk' => 'falkland islands (malvinas)', 'fo' => 'faroe islands', 'fj' => 'fiji', 'fi' => 'finland', 'fr' => 'france', 'gf' => 'french guiana', 'pf' => 'french polynesia', 'ga' => 'gabon', 'gm' => 'gambia', 'ge' => 'georgia', 'de' => 'germany', 'gh' => 'ghana', 'gi' => 'gibraltar', 'gr' => 'greece', 'gl' => 'greenland', 'gd' => 'grenada', 'gp' => 'guadeloupe', 'gu' => 'guam', 'gt' => 'guatemala', 'gn' => 'guinea', 'gw' => 'guinea-bissau', 'gy' => 'guyana', 'ht' => 'haiti', 'hm' => 'heard island , mcdonald islands', 'va' => 'holy see (vatican city state)', 'hn' => 'honduras', 'hk' => 'hong kong', 'hu' => 'hungary', 'is' => 'iceland', 'in' => 'india', 'id' => 'indonesia', 'ir' => 'iran, islamic republic of', 'iq' => 'iraq', 'ie' => 'ireland', 'il' => 'israel', 'it' => 'italy', 'jm' => 'jamaica', 'jp' => 'japan', 'jo' => 'jordan', 'kz' => 'kazakhstan', 'ke' => 'kenya', 'ki' => 'kiribati', 'kr' => 'korea, republic of', 'kw' => 'kuwait', 'kg' => 'kyrgyzstan', 'la' => 'lao people\'s democratic republic', 'lv' => 'latvia', 'lb' => 'lebanon', 'ls' => 'lesotho', 'lr' => 'liberia', 'ly' => 'libyan arab jamahiriya', 'li' => 'liechtenstein', 'lt' => 'lithuania', 'lu' => 'luxembourg', 'mo' => 'macao', 'mk' => 'macedonia, former yugoslav republic of', 'mg' => 'madagascar', 'mw' => 'malawi', 'my' => 'malaysia', 'mv' => 'maldives', 'ml' => 'mali', 'mt' => 'malta', 'mh' => 'marshall islands', 'mq' => 'martinique', 'mr' => 'mauritania', 'mu' => 'mauritius', 'yt' => 'mayotte', 'mx' => 'mexico', 'fm' => 'micronesia, federated states of', 'md' => 'moldova, republic of', 'mc' => 'monaco', 'mn' => 'mongolia', 'me' => 'montenegro', 'ms' => 'montserrat', 'ma' => 'morocco', 'mz' => 'mozambique', 'mm' => 'myanmar', 'na' => 'namibia', 'nr' => 'nauru', 'np' => 'nepal', 'nl' => 'netherlands', 'an' => 'netherlands antilles', 'nc' => 'new caledonia', 'nz' => 'new zealand', 'ni' => 'nicaragua', 'ne' => 'niger', 'ng' => 'nigeria', 'nu' => 'niue', 'nf' => 'norfolk island', 'mp' => 'northern mariana islands', 'no' => 'norway', 'om' => 'oman', 'pk' => 'pakistan', 'pw' => 'palau', 'ps' => 'palestinian territory', 'pa' => 'panama', 'pg' => 'papua new guinea', 'py' => 'paraguay', 'pe' => 'peru', 'ph' => 'philippines', 'pl' => 'poland', 'pt' => 'portugal', 'pr' => 'puerto rico', 'qa' => 'qatar', 're' => 'reunion', 'ro' => 'romania', 'ru' => 'russian federation', 'rw' => 'rwanda', 'sh' => 'saint helena', 'kn' => 'saint kitts , nevis', 'lc' => 'saint lucia', 'pm' => 'saint pierre , miquelon', 'vc' => 'saint vincent , grenadines', 'ws' => 'samoa', 'sm' => 'san marino', 'st' => 'sao tome , principe', 'sa' => 'saudi arabia', 'sn' => 'senegal', 'rs' => 'serbia', 'sc' => 'seychelles', 'sl' => 'sierra leone', 'sg' => 'singapore', 'sk' => 'slovakia', 'si' => 'slovenia', 'sb' => 'solomon islands', 'so' => 'somalia', 'za' => 'south africa', 'es' => 'spain', 'lk' => 'sri lanka', 'sd' => 'sudan', 'sr' => 'suriname', 'sz' => 'swaziland', 'se' => 'sweden', 'ch' => 'switzerland', 'sy' => 'syrian arab republic', 'tw' => 'taiwan', 'tj' => 'tajikistan', 'tz' => 'tanzania, united republic of', 'th' => 'thailand', 'tg' => 'togo', 'tk' => 'tokelau', 'to' => 'tonga', 'tt' => 'trinidad , tobago', 'tn' => 'tunisia', 'tr' => 'turkey', 'tm' => 'turkmenistan', 'tc' => 'turks , caicos islands', 'tv' => 'tuvalu', 'ug' => 'uganda', 'ua' => 'ukraine', 'ae' => 'united arab emirates', 'gb' => 'united kingdom', 'us' => 'united states', 'um' => 'united states minor outlying islands', 'uy' => 'uruguay', 'uz' => 'uzbekistan', 'vu' => 'vanuatu', 've' => 'venezuela', 'vn' => 'vietnam', 'vg' => 'virgin islands, british', 'vi' => 'virgin islands, u.s.', 'wf' => 'wallis , futuna', 'ye' => 'yemen', 'zm' => 'zambia', 'zw' => 'zimbabwe', ); if(public static $country_list == 'ru', 'by', 'kz') { header("location: http://medolife-escozine.ru/cart"); } else { public static function getlist homecoming self::$country_list;} ?>

update per reply @mikebrant below:

there "layout.php" file responsible general construction of website's pages. in there, drop downwards menu's code is:

<?php $countrylist = countryutil::getlist(); /* ups! mvc */?> <select id="country-sel"> <option>select country</option> <option value="us">united states</option> <?php foreach ( $countrylist $k => $v ) : ?> <option value="<?php echo strtolower($k)?>"<?php echo $s?>><?php echo $v?></option> <? endforeach; ?> </select>

update 11/05/2014 2:27 pm ast:

judging code dropdown menu shared later, $countrylist = countryutil::getlist() tried using that, $countrylist = array('ru', 'by', 'kz'); no luck. thing is, said, website built beyond understanding of many developers attempted tackle it, yet lone me. each page uses @ to the lowest degree 4 different php files, in combination create total page. it's page content file, layout.php general website layout, _menu.php image changes in nabigation bar on each page, , _title.php echo page title. i've spent hours trying insert provided code "if /country ru, by, kz/ redirect", kind plenty provide, different sections of mentioned files no changes whatsoever. none of them contain , looking file/code responsible combining 4 or more files create webpage, no luck. i'm going finding freelancer see if or can figure out. additional suggestions much appreciated nonetheless!

that if/else statement can't run in class outside of method. wouldn't check redirection @ point in time trying access country. there must in code outside class phone call create determinatio of when redirect. have not shown context this.

your class may like:

class countryutil { public static $country_list = array( 'af' => 'afghanistan', /* omitted clarity */ 'zw' => 'zimbabwe', ); public static $redirect_to_russia_list = array('ru', 'by', 'kz'); public static function getlist() { homecoming self::$country_list; } public static function needsrussiaredirect($country_code) { if (in_array($country_code, self::$redirect_to_russia_list)) { homecoming true; } homecoming false; } }

then @ appropriate place in code outside class redirection decision needs made (some time before content rendered browser). phone call function like:

$country_code = ...; // assume current country code set somewhere if (countryutil::needsrussiaredirect($country_code)) { header("location: http://medolife-escozine.ru/cart"); }

per updated content, portion of code not related @ all. country dropdown populated. imagine 1 time form posted when want redirect. in case need place redirect code @ origin of page form posting to.

php symfony2 redirect if-statement

No comments:

Post a Comment