Skip to main content
Topic: Phprad Global functions (Read 7846 times) previous topic - next topic

Phprad Global functions

Phprad Global functions

Please Note: This Constant can be accessed in any Page or PHP Class.

USER_ID
Return Active User ID if logged in

USER_NAME
Return Active User Name if logged in

USER_PHOTO
Return Active User photo if logged in

USER_EMAIL
Return Active User Email if logged in

USER_ROLE
Return Active User Role if logged in

SITE_NAME
Return Application|Site Name

SITE_ADDR
Return site Address
Example http://localhost/sitename/

SITE_LOGO
Return site logo image src
Example http://localhost/sitename/assets/images/logo.png

SITE_FAVICON
Return site favion image src
Example http://localhost/sitename/assets/images/favicon.png


Helper Function
Please these functions are to be used at the server side

get_active_user($field=null)
Get Logged In User Details From The Session
Get particular field value of the active user otherwise return array of active user fields
Return Value Type: array | string
echo get_active_user('user_city');

user_login_status()
Check if there is active User Logged In
Return Value Type: boolean

authenticate_user()
Authenticate And Check User Page Access Eligibility
Return Value Type: Redirect to Login Page Or Displays Error Message When user access control authorization Fails

is_mobile()
Check if current browser platform is a mobile browser
Can Be Used to Switch Layouts and Views on A Mobile Platform
Return Value Type: boolean

print_link($path=null)
Echo Absolute Url Address of a path
Example : <a href="<?php print_link('users/add'); ?>">Add Users</a>

set_url($path=null)
Return Absolute Url Address of a path

set_img_src($imgsrc,$width=null,$height=null)
Convinient Function To Resize Image Via Url of the Image Src if the src is from the same origin then image can be resize
Example : <img src="<?php echo set_img_src('uploads/images/89njdh4533.jpg',50,50); ?>" />;

datetime_now()
will return current DateTime in Mysql Default Date Time Format (Y-m-d H:i:s)
Example : 2017-02-13 03:15:00

time_now()
will return current Time in Mysql Default Date Time Format (H:i:s)
Example : 03:15:00

date_now()
will return current Date in Mysql Default Date Time Format (Y-m-d)
Example: 2017-02-13

relative_time($date=null)
Parse Date Or Timestamp Object into Relative Time
Example : 2 days ago 2 days from now

human_date($date=null)
Parse Date Or Timestamp Object into Human Readable Date
Example : 26th of March 2016

human_datetime($date=null)
Parse Date Or Timestamp Object into Human Readable Date
Example : 26th of March 2016 02:30 pm

random_chars($limit=12,$context='...')
Generate a Random String and characters From Set Of supplied data context
Example : f#8Gt4!a@hdt

random_str($limit=12,$context='...')
Generate a Random String From Set Of supplied data context
Example : Ga89KJ67adf4

random_num($limit=6,$context='1234567890')
Generate a Random Number From Set Of Supplied Numbers
Example : 681423

random_color($alpha=1)
Generate a Random color String
Example : rgba(230,12,9,0.5)

set_flash_msg($msg,$type="success",$dismissable=true,$showduration=5000)
Set Msg that Will be Display to User in a Session.
Can Be Displayed on Any View.

show_flash_msg()
Display The Message Set In MsgFlash Session On Any Page.
Will Clear The Message Afterwards

redirect_to_page($path=null)
Convinient Function To Redirect to Another Page
Example : redirect_to_page("users/view/".USER_ID);  Should not be use in view pages. Only in Controller page

redirect_to_action($action_name=null)
Convinient Function To Redirect to Page Action
Example redirect_to_action('add');  Should not be use in view pages. Only in Controller page

redirect($url)
Convenient Function To Redirect to External URL
Should not be used in view pages. Only in Controller page

approximate($val, $decimal_points=2)
Approximate to nearest decimal points
Example 3784.7466477 » 3784.75

to_currency($val, $lang = 'en-US')
Format string to country currency
Example 5000 » $5,000

to_number($val, $lang = 'en-US')
return a numerical representation of the string grouped in different units
Example 247704360 » 247,704,360

str_truncate($string, $length=50, $ellipse= '...')
Trucate string
Example This is PhpRad Classic » This is PhpRad...

number_to_words($val,$lang="en")
Convert numerical value to word representation
Example 247704360 » two hundred forty-seven million seven hundred four thousand three hundred sixty

set_cookie($name,$value,$days=30)
Set a browser cookie

get_cookie($name)
Return a cookie value

clear_cookie($name)
Delete a cookie

http_post($name)
Convenient function to retrieve content of from external Url Using CURL POST Request

http_get($name,$params=array())
Convenient function to retrieve content of from external Url Using CURL GET RequestA