Code:PHP Functions
Contents |
Disclaimer
These Functions and Classes are Available As Is, you may use them anywhere, so Long as you add a small link here and a link to the BSD license in a comment. There is no guarantee associated with these functions, they are used in working scripts, so please do not flood me with "Your Code has an Error" messages because it doesn't :-P.
Functions
Check IE
This will check your visitor's User Agent, allowing you to specify different class(es) for users with Internet Exploder.
function chkIe($class) { /* Usage: <div class="<?php echo chkIe($classname);?>"> Insert the Element(s) IE doesn't render right. </div> Of course any element that can use the class attribute may be used. */ $agent = $_SERVER['HTTP_USER_AGENT']; if (preg_match("/MSIE/", $agent)) { $r = $class . "_ie"; } else { $r = $class; } return $r; }
Get Home
For Shared Hosts who's web root is as similar to /home/user/public_html/
function getHome (){ $home_array = $_SERVER['SCRIPT_FILENAME']; $home_split = split ('/', $home_array); $home = "/".$home_split['1']."/".$home_split['2']; return $home; }
Test if Curl is working
Make sure the cURL PHP Extension is functioning properly on a server.
function testCurl() { // Can work with HTTPS also $user = ""; // For any 401 Response $pass = ""; // Also for any 401 Response. $url = "http://www.google.com/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass"); //Use this if a 401 Response is given if($data = curl_exec($ch) === false) { echo 'Curl error: ' . curl_error($ch); } else { print "Data: \n"; print $data; } }
Licensing
Copyright (c) 2008-2009, Zoelife4u.Org All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the Zoelife4U.Org nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.