PHP to delete cookie in php class - php

I am about to control my pages content. so that I need add or delete sessions/cookies. I maked a class that is working fine but in the cookie issue, it is not working as well. I checked with firefox 18 in windows7, and ubuntu 12.04 LTS. the cookies are not deleted using
setcookie(name, '', time()-9600)
foreach($this->_ck as $cookie)
{
$hrs=0;
if($plus)
{
$hrs=3600*$cfg_cookie_time;
}
//setcookie('testcookie13', '', time()-3600*6);
header("Set-Cookie: ".$cookie."=deleted; expires=Sun, 01-Jul-2012 08:59:12 GMT;");
}
etc...
My class is:
<?php
class headers{
var $new;
var $vars;
var $ss;
var $ck;
var $_ss;
var $_ck;
var $error;
var $catchs;
function _construct()
{
$this->new=false;
$this->error=false;
$this->ss=array();
$this->ck=array();
$this->_ss=array();
$this->_ck=array();
$this->catchs=true;
return $this->catchs;
} //f
function headers($hs = array(
"set" => array(
"ss" => array(),
"ck" => array()
)
))
{
if(isset($hs['send']))
{
$this->new=$hs['send'];
$this->catchs=true;
}
if(is_array($hs['set']))
{
if(is_array($hs['set']['ss']))
{
$this->ss = $hs['set']['ss'];
}
if(is_array($hs['set']['ck']))
{
$this->ck = $hs['set']['ck'];
}
}
if(is_array($hs['unset']))
{
if($hs['unset']['ss'])
{
$this->_ss = $hs['unset']['ss'];
}
if(is_array($hs['unset']['ck']))
{
$this->_ck = $hs['unset']['ck'];
}
}
return $this->catchs;
} //f
function send(
$cfg_cookie_time=6,
$plus=true
)
{
$cookie='';
if(is_array($this->ss))
{
session_start();
foreach($this->ss as $session){
$_SESSION['session'] = $session;
}
}
if($this->_ck)
{
foreach ($_COOKIE as $name => $value) {
setcookie($name, '', 1);
}
}
if($this->ck)
{
foreach($this->ck as $cookie => $val)
{
//$this->ck=$cookie.$val;
$hrs=0;
if($plus)
{
$hrs=3600*$cfg_cookie_time;
}
header("Set-Cookie: ".$cookie."=".$val."; path=/; domain=".$_SERVER['HTTP_HOST']."; expires=".gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT;", time()+$hrs));
}
}
if($this->new)
{
header("location: ".$this->new);
$this->catchs=false;
}
header("X-Powered-By: PHP ".phpversion()."/FxPHP");
//header("HTTP/1.0 404 Not Found");
return $this->ck;
} //f
} // class
setcookie('H', '', -3600);
/*$hr = new HEADERS( array
(
"set" => array
(
"ck"=> array(),
"ss"=> array()
),
"unset" => array
(
"ck"=> array
(
"H" => "H"
),
"ss"=> array()
)
)
);
print_r( $_COOKIE).print_r($hr->send());
/*
" f" => "" ,
" sf" => "",
"my"=> "" ,
print_r(getallheaders());
print_r(setcookie('sd', 'dsds', 3600*6));
*/
?>
Can you any help?

Try it:
<?php
function del_cookie($_cookie = array())
{
foreach($_cookie as $k => $kv)
{
setcookie($k, '', time()-3600);
}
return;
}
function add_cookie($_cookie)
{
foreach($_cookie as $k => $kv)
{
setcookie($k, $kv, time()+3600*24*6);
}
return;
}
class headers{
var $new;
var $vars;
var $ss;
var $ck;
var $_ss;
var $_ck;
var $_ak;
var $_dk;
var $error;
var $catchs;
function _constract()
{
$this->new=false;
$this->error=false;
$this->ss=array();
$this->ck=array();
$this->_ss=array();
$this->_ck=array();
$this->catchs=true;
$this->_ak = false;
$this->_dk = false;
return $this->catchs;
} //f
function headers($hs = array(
"set" => array(
"ss" => array(),
"ck" => array()
)
))
{
if(isset($hs['send']))
{
$this->new=$hs['send'];
$this->catchs=true;
}
if($hs['set']['ck']['true'])
{
$this->ck = $hs['set']['ck'];
$this->_ak = true;
}
/*if($hs['unset']['ss'])
{
$this->_ss = $hs['unset']['ss'];
}
*/
if($hs['unset']['ck']['true'])
{
$this->_ck = $hs['unset']['ck'];
$this->_dk = true;
}
return $this->catchs;
} //f
function send(
$cfg_cookie_time=6,
$plus=true
)
{
if(is_array($this->ss))
{
session_start();
foreach($this->ss as $session){
$_SESSION['session'] = $session;
}
}
if($this->_dk)
{
del_cookie($this->_ck);
}
if($this->_ak)
{
add_cookie($this->ck);
}
if($this->new)
{
header("location: ".$this->new);
$this->catchs=false;
}
header("X-Powered-By: PHP ".phpversion()."/FxPHP");
//header("HTTP/1.0 404 Not Found");
return $this->catchs;
} //f
} // class
$hr = new HEADERS( array
(
"set" => array
(
"ck"=> array(
"true" => ""
),
"ss"=> array
(
"true" => "")
),
"unset" => array
(
"ck"=> array
(
"true" => "YES",
"Test" => "1"
),
"ss"=> array
(
"true" => "")
)
)
);
print_r( $_COOKIE).print_r($hr->send());
/*
" f" => "" ,
" sf" => "",
"my"=> "" ,
print_r(getallheaders());
print_r(setcookie('sd', 'dsds', 3600*6));
*/
?>

One error I see in your code is
function _constract()
which should be
function __construct()

setcookie($cookie_name, null, null);
Will delete a cookie no matter what. Use that in plain php in the beginning of a script before any logic to verify that. If you're using this and your cookies are not being deleted you're either using xml requests or you have some issues in your logic. Good luck!

Related

How to use this php class

I need to use the functions of this class,I wrote a code but the output was empty,need echo data from all functions.
I correctly entered the connection requirements,script use Json-rpc for request,The port is open on the server
I don't know how to use this class
my class
<?php
require_once("jsonrpc.inc");
class IBSjsonrpcClient {
function IBSjsonrpcClient($server_ip="127.0.0.1", $auth_name="user", $auth_pass="pass", $auth_type="ADMIN", $server_port="1237", $timeout=1800){
$this->client = new jsonrpc_client($server_ip. ':' . $server_port);
$this->auth_name = $auth_name;
$this->auth_pass = $auth_pass;
$this->auth_type = $auth_type;
$this->timeout = $timeout;
}
function sendRequest($server_method, $params_arr){
/*
Send request to $server_method, with parameters $params_arr
$server_method: method to call ex admin.addNewAdmin
$params_arr: an array of parameters
*/
$params_arr["auth_name"] = $this->auth_name;
$params_arr["auth_pass"] = $this->auth_pass;
$params_arr["auth_type"] = $this->auth_type;
$response = $this->client->send($server_method, $params_arr, $this->timeout);
$result = $this->__returnResponse($response);
unset($response);
return $result;
}
function __returnResponse($response){
if ($response == FALSE)
return $this->__returnError("Error occured while connecting to server");
else if ($response->faultCode() != 0)
return $this->__returnError($response->faultString());
else
return $this->__returnSuccess($response->value());
}
function __returnError($err_str){
return array(FALSE, $err_str);
}
function __returnSuccess($value){
return array(TRUE, $value);
}
function getUserInfoByUserID($user_id){
return $this->sendRequest("user.getUserInfo", array("user_id"=>(string)$user_id));
}
function getUserInfoByNormalUserName($normal_username){
return $this->sendRequest("user.getUserInfo", array("normal_username"=>$normal_username));
}
function getBasicUserInfoByNormalUserName($normal_username){### for Zahedan Telecom, ticket 34083
$result = $this->sendRequest("user.getUserInfo", array("normal_username"=>$normal_username));
if(!$result[0]){
return $result;
}
$info = $result[1];
return array(
"user_id" => $info["basic_info"]["user_id"],
"normal_username" => $info["attrs"]["normal_username"],
"remaining_days" => $info["remaining_days"],
"remaining_mega_bytes" => $info["remaining_mega_bytes"],
"credit" => $info["basic_info"]["credit"],
"group_name" => $info["basic_info"]["group_name"]
);
}
function getUserInfoBySerial($serial){
return $this->sendRequest("user.getUserInfo", array("serial"=>$serial));
}
function addNewUser($count, $credit, $isp_name, $group_name, $credit_comment=""){
return $this->sendRequest("user.addNewUsers", array(
"count" => $count,
"credit" => $credit,
"isp_name" => $isp_name,
"group_name" => $group_name,
"credit_comment" => $credit_comment
));
}
function setNormalUserAuth($user_id, $username, $password){
return $this->setUserAttributes($user_id, array(
"normal_user_spec" => array(
"normal_username"=>$username,
"normal_password"=>$password,
)
));
}
}
?>
example code for use function in class but empty array
<?php
require "ibs-jsonrpc-client.php";
$ibs = new IBSjsonrpcClient();
$a = $ibs->getBasicUserInfoByNormalUserName("user1");
print_r($a);
?>

How do I return a variable instead of a string?

In this example, the function validateJsonNotEmptyImage does not work as expected?
Just to clarify.
'src' => $image->src, // WORKS
'height' => $this->validateJsonNotEmptyImage('type', 'width'), // DOES NOT WORK
public function validateJsonNotEmptyImage($type, $array1) {
if ($type, $array1) {
if (isset($type->$array1)) {
return $type . '->' . $array1;
} else {
return null;
}
}
}
$productsImagesToSiteArray = array();
foreach ($this->resource->images as $image) {
$productsImagesToSiteArray[] = array(
'height' => $this->validateJsonNotEmptyImage('$image', 'width'),
'src' => $image->src,
);
}
I see two mistakes
1) your method validateJsonNotEmptyImage, in body you have wrong IF it should be check with null[here1] and you should return value not string[here2].
And also you should return everytime any value or null[here3].
public function validateJsonNotEmptyImage($type, $array1) {
if ($type != null && $array1 != null) { <----------- here1
if (isset($type->$array1)) {
return $type->$array1; <----------- here2
} else {
return null;
}
}
return null; <----------- here3
}
2) you should pass variable not string in your call (remove quotes from $image)
$this->validateJsonNotEmptyImage($image, 'width')

How to make hyperlink from author name in Wordpress?

I'm a total newbie to Wordpress and having a hard time figuring things out.
I'm using plugin called "WP-Pro-Quiz", a quiz plugin, and within the plugin there's an option to show "Leaderboard" of all users who completed the quiz. In the leaderboard on the frontend, there's user id, time, points and user's Display Name, etc for each user..
What I want to achieve is to make Display name clickable (and then to go to author's profile once clicked). That is, to connect Display Name with author profile who took the quiz, to create hyperlink from Display Name.
This is from controller WpProQuiz_Controller_Toplist.php :
<?php
class WpProQuiz_Controller_Toplist extends WpProQuiz_Controller_Controller
{
public function route()
{
$quizId = $_GET['id'];
$action = isset($_GET['action']) ? $_GET['action'] : 'show';
switch ($action) {
default:
$this->showAdminToplist($quizId);
break;
}
}
private function showAdminToplist($quizId)
{
if (!current_user_can('wpProQuiz_toplist_edit')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
$view = new WpProQuiz_View_AdminToplist();
$quizMapper = new WpProQuiz_Model_QuizMapper();
$quiz = $quizMapper->fetch($quizId);
$view->quiz = $quiz;
$view->show();
}
public function getAddToplist(WpProQuiz_Model_Quiz $quiz)
{
$userId = get_current_user_id();
if (!$quiz->isToplistActivated()) {
return null;
}
$data = array(
'userId' => $userId,
'token' => wp_create_nonce('wpProQuiz_toplist'),
'canAdd' => $this->preCheck($quiz->getToplistDataAddPermissions(), $userId),
);
if ($quiz->isToplistDataCaptcha() && $userId == 0) {
$captcha = WpProQuiz_Helper_Captcha::getInstance();
if ($captcha->isSupported()) {
$data['captcha']['img'] = WPPROQUIZ_CAPTCHA_URL . '/' . $captcha->createImage();
$data['captcha']['code'] = $captcha->getPrefix();
}
}
return $data;
}
private function handleAddInToplist(WpProQuiz_Model_Quiz $quiz)
{
if (!wp_verify_nonce($this->_post['token'], 'wpProQuiz_toplist')) {
return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true);
}
if (!isset($this->_post['points']) || !isset($this->_post['totalPoints'])) {
return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true);
}
$quizId = $quiz->getId();
$userId = get_current_user_id();
$points = (int)$this->_post['points'];
$totalPoints = (int)$this->_post['totalPoints'];
$name = !empty($this->_post['name']) ? trim($this->_post['name']) : '';
$email = !empty($this->_post['email']) ? trim($this->_post['email']) : '';
$ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP);
$captchaAnswer = !empty($this->_post['captcha']) ? trim($this->_post['captcha']) : '';
$prefix = !empty($this->_post['prefix']) ? trim($this->_post['prefix']) : '';
$quizMapper = new WpProQuiz_Model_QuizMapper();
$toplistMapper = new WpProQuiz_Model_ToplistMapper();
if ($quiz == null || $quiz->getId() == 0 || !$quiz->isToplistActivated()) {
return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true);
}
if (!$this->preCheck($quiz->getToplistDataAddPermissions(), $userId)) {
return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true);
}
$numPoints = $quizMapper->sumQuestionPoints($quizId);
if ($totalPoints > $numPoints || $points > $numPoints) {
return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true);
}
$clearTime = null;
if ($quiz->isToplistDataAddMultiple()) {
$clearTime = $quiz->getToplistDataAddBlock() * 60;
}
if ($userId > 0) {
if ($toplistMapper->countUser($quizId, $userId, $clearTime)) {
return array('text' => __('You can not enter again.', 'wp-pro-quiz'), 'clear' => true);
}
$user = wp_get_current_user();
$email = $user->user_email;
$name = $user->display_name;
} else {
if ($toplistMapper->countFree($quizId, $name, $email, $ip, $clearTime)) {
return array('text' => __('You can not enter again.', 'wp-pro-quiz'), 'clear' => true);
}
if (empty($name) || empty($email) || filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
return array('text' => __('No name or e-mail entered.', 'wp-pro-quiz'), 'clear' => false);
}
if (strlen($name) > 15) {
return array('text' => __('Your name can not exceed 15 characters.', 'wp-pro-quiz'), 'clear' => false);
}
if ($quiz->isToplistDataCaptcha()) {
$captcha = WpProQuiz_Helper_Captcha::getInstance();
if ($captcha->isSupported()) {
if (!$captcha->check($prefix, $captchaAnswer)) {
return array('text' => __('You entered wrong captcha code.', 'wp-pro-quiz'), 'clear' => false);
}
}
}
}
$toplist = new WpProQuiz_Model_Toplist();
$toplist->setQuizId($quizId)
->setUserId($userId)
->setDate(time())
->setName($name)
->setEmail($email)
->setPoints($points)
->setResult(round($points / $totalPoints * 100, 2))
->setIp($ip);
$toplistMapper->save($toplist);
return true;
}
private function preCheck($type, $userId)
{
switch ($type) {
case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_TYPE_ALL:
return true;
case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_TYPE_ONLY_ANONYM:
return $userId == 0;
case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_TYPE_ONLY_USER:
return $userId > 0;
}
return false;
}
public static function ajaxAdminToplist($data)
{
if (!current_user_can('wpProQuiz_toplist_edit')) {
return json_encode(array());
}
$toplistMapper = new WpProQuiz_Model_ToplistMapper();
$j = array('data' => array());
$limit = (int)$data['limit'];
$start = $limit * ($data['page'] - 1);
$isNav = isset($data['nav']);
$quizId = $data['quizId'];
if (isset($data['a'])) {
switch ($data['a']) {
case 'deleteAll':
$toplistMapper->delete($quizId);
break;
case 'delete':
if (!empty($data['toplistIds'])) {
$toplistMapper->delete($quizId, $data['toplistIds']);
}
break;
}
$start = 0;
$isNav = true;
}
$toplist = $toplistMapper->fetch($quizId, $limit, $data['sort'], $start);
foreach ($toplist as $tp) {
$j['data'][] = array(
'id' => $tp->getToplistId(),
'name' => $tp->getName(),
'email' => $tp->getEmail(),
'type' => $tp->getUserId() ? 'R' : 'UR',
'date' => WpProQuiz_Helper_Until::convertTime($tp->getDate(),
get_option('wpProQuiz_toplistDataFormat', 'Y/m/d g:i A')),
'points' => $tp->getPoints(),
'result' => $tp->getResult()
);
}
if ($isNav) {
$count = $toplistMapper->count($quizId);
$pages = ceil($count / $limit);
$j['nav'] = array(
'count' => $count,
'pages' => $pages ? $pages : 1
);
}
return json_encode($j);
}
public static function ajaxAddInToplist($data)
{
// workaround ...
$_POST = $_POST['data'];
$ctn = new WpProQuiz_Controller_Toplist();
$quizId = isset($data['quizId']) ? $data['quizId'] : 0;
$prefix = !empty($data['prefix']) ? trim($data['prefix']) : '';
$quizMapper = new WpProQuiz_Model_QuizMapper();
$quiz = $quizMapper->fetch($quizId);
$r = $ctn->handleAddInToplist($quiz);
if ($quiz->isToplistActivated() && $quiz->isToplistDataCaptcha() && get_current_user_id() == 0) {
$captcha = WpProQuiz_Helper_Captcha::getInstance();
if ($captcha->isSupported()) {
$captcha->remove($prefix);
$captcha->cleanup();
if ($r !== true) {
$r['captcha']['img'] = WPPROQUIZ_CAPTCHA_URL . '/' . $captcha->createImage();
$r['captcha']['code'] = $captcha->getPrefix();
}
}
}
if ($r === true) {
$r = array('text' => __('You signed up successfully.', 'wp-pro-quiz'), 'clear' => true);
}
return json_encode($r);
}
public static function ajaxShowFrontToplist($data)
{
// workaround ...
$_POST = $_POST['data'];
$quizIds = empty($data['quizIds']) ? array() : array_unique((array)$data['quizIds']);
$toplistMapper = new WpProQuiz_Model_ToplistMapper();
$quizMapper = new WpProQuiz_Model_QuizMapper();
$j = array();
foreach ($quizIds as $quizId) {
$quiz = $quizMapper->fetch($quizId);
if ($quiz == null || $quiz->getId() == 0) {
continue;
}
$toplist = $toplistMapper->fetch($quizId, $quiz->getToplistDataShowLimit(), $quiz->getToplistDataSort());
foreach ($toplist as $tp) {
$j[$quizId][] = array(
'name' => $tp->getName(),
'date' => WpProQuiz_Helper_Until::convertTime($tp->getDate(),
get_option('wpProQuiz_toplistDataFormat', 'Y/m/d g:i A')),
'points' => $tp->getPoints(),
'result' => $tp->getResult()
);
}
}
return json_encode($j);
}
}
and from model WpProQuiz_Model_Toplist.php:
<?php
class WpProQuiz_Model_Toplist extends WpProQuiz_Model_Model
{
protected $_toplistId;
protected $_quizId;
protected $_userId;
protected $_date;
protected $_name;
protected $_email;
protected $_points;
protected $_result;
protected $_ip;
public function setToplistId($_toplistId)
{
$this->_toplistId = (int)$_toplistId;
return $this;
}
public function getToplistId()
{
return $this->_toplistId;
}
public function setQuizId($_quizId)
{
$this->_quizId = (int)$_quizId;
return $this;
}
public function getQuizId()
{
return $this->_quizId;
}
public function setUserId($_userId)
{
$this->_userId = (int)$_userId;
return $this;
}
public function getUserId()
{
return $this->_userId;
}
public function setDate($_date)
{
$this->_date = (int)$_date;
return $this;
}
public function getDate()
{
return $this->_date;
}
public function setName($_name)
{
$this->_name = (string)$_name;
return $this;
}
public function getName()
{
return $this->_name;
}
public function setEmail($_email)
{
$this->_email = (string)$_email;
return $this;
}
public function getEmail()
{
return $this->_email;
}
public function setPoints($_points)
{
$this->_points = (int)$_points;
return $this;
}
public function getPoints()
{
return $this->_points;
}
public function setResult($_result)
{
$this->_result = (float)$_result;
return $this;
}
public function getResult()
{
return $this->_result;
}
public function setIp($_ip)
{
$this->_ip = (string)$_ip;
return $this;
}
public function getIp()
{
return $this->_ip;
}
}

get faster results, reduce load time php

I have written this function:
public function returnAllFeeds($responseType = RESPONSE_RETURN)
{
$twitter = $this->getTwitterFeeds();
$instagram = $this->getInstagramFeeds();
$facebook = $this->getFacebookResponse();
$allFeeds = $this->sortNjoin($twitter,$instagram, $facebook);
if($responseType == RESPONSE_JSON)
{
echo json_encode($allFeeds);
}
else
{
return $allFeeds;
}
}
where all the feeds from twitter, facebook and instagram is fetched but everytime php gets data it takes atleast 5-6 seconds, so i wanna know if their is a way to reduce curl fetching time.
here's more code:
public function getFacebookResponse($responseType = RESPONSE_RETURN)
{
$params = array(
'access_token' => FACEBOOK_TOKEN,
'limit' => '30',
'fields' => 'message,permalink_url,id,from,name,picture,source,updated_time'
);
$fbFeeds[] = $this->curl_library->getFacebookPosts('godoolallyandheri',$params);
$fbFeeds[] = $this->curl_library->getFacebookPosts('godoolallybandra',$params);
$fbFeeds[] = $this->curl_library->getFacebookPosts('godoolally',$params);
if($responseType == RESPONSE_JSON)
{
echo json_encode($fbFeeds);
}
else
{
return array_merge($fbFeeds[0]['data'],$fbFeeds[1]['data'],$fbFeeds[2]['data']);
}
}
public function getTwitterFeeds($responseType = RESPONSE_RETURN)
{
$twitterFeeds = '';
$this->twitter->tmhOAuth->reconfigure();
$parmas = array(
'count' => '61',
'exclude_replies' => 'true',
'screen_name' => 'godoolally'
);
$responseCode = $this->twitter->tmhOAuth->request('GET','https://api.twitter.com/1.1/statuses/user_timeline.json',$parmas);
if($responseCode == 200)
{
$twitterFeeds = $this->twitter->tmhOAuth->response['response'];
}
$twitterFeeds = json_decode($twitterFeeds,true);
if($responseType == RESPONSE_JSON)
{
echo json_encode($twitterFeeds);
}
else
{
return $twitterFeeds;
}
}
public function getInstagramFeeds($responseType = RESPONSE_RETURN)
{
$instaFeeds = $this->curl_library->getInstagramPosts();
if(!myIsMultiArray($instaFeeds))
{
$instaFeeds = null;
}
else
{
$instaFeeds = $instaFeeds['posts']['items'];
}
if($responseType == RESPONSE_JSON)
{
echo json_encode($instaFeeds);
}
else
{
return $instaFeeds;
}
}
not really concern with sortNJoin it takes only ms to perform

How do I write code without a foreach loop?

How do I write this code without a foreach loop? I want to fetch the data from the database, but the key and value are stored in the database.
<?php
$options = get_payment_mode_options();
foreach ($options as $key => $value)
{
echo isset($form_data["personal_info"]) && $form_data["personal_info"]->payment_mode == $key ? $value : "";
}
?>
get_payment_mode_options() is function in helper,
function get_payment_mode_options()
{
return array(
"o" => "Online Payment",
"c" => "Cheque Payment"
);
}
Check this,
$options = get_payment_mode_options();
$paymentmode = isset($form_data["personal_info"]) ? $form_data["personal_info"]->payment_mode : '';
echo $options[$paymentmode];
helper function
function get_payment_mode_options()
{
return array(
"o" => "Online Payment",
"c" => "Cheque Payment"
);
}
<?php
function get_payment_mode_options()
{
return array(
"o" => "Online Payment",
"c" => "Cheque Payment"
);
}
// make a new function
function get_your_result($your_key)
{
if (!$your_key) {
return "";
}
$options = get_payment_mode_options();
if(!array_key_exists($your_key,$options)){
return "";
}
return $options[$your_key];
}
// dummy for test
$form_data["personal_info"] = new stdClass();
$form_data["personal_info"]->payment_mode = "o";
$k = $form_data["personal_info"]->payment_mode;
// ~dummy for test
// echo result
echo "----".PHP_EOL;
echo get_your_result($k).PHP_EOL;
echo "----".PHP_EOL;

Categories