Jump to content

Check out our Community Blogs


Member Since 20 Mar 2010
Offline Last Active Aug 02 2012 11:51 AM

Topics I've Started

htaccess mod_rewrite question

13 January 2012 - 07:51 AM

Hey guys/gals,

I am using this code for my redirects:
# Redirect for health-it aliases
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(healthit|health_it)/ [NC]
RewriteRule ^(healthit|health_it)/(.+)$ /health-it/$2 [NC,L,R=301]

# Load pages for health-it while keeping the URL masked
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/health-it/ [NC]
RewriteRule ^health-it/(.+)$ /health-it/loadPage.php?p=$1 [NC,L]

The first redirect just redirects the possible aliases to the correct URI and this works fine ( I only included it because I felt it was worth including), it's the second one I am having trouble with.
On my localhost this redirect works properly but once live, it acts different.
The URL structure I am expecting (and I get on my localhost) is :
This will load this particular sub-system (with or without the trailing /). The issue I am having is, once live, if the URI is missing the trailing slash it gives me this:
I am completely baffled by this because I do not have this happen on my local dev and I actually had to resolve that issue before and it worked fine. The issue is on my live server. Can anyone spot why this is happening? I am really puzzled and I cannot figure this out so I thought some fresh eyes may be able to help resolve this.

Thanks in advanced :)

PHP Cookie Object

04 January 2012 - 08:50 AM

Here is a cookie object I use for my applications.
I decided to share this with the community as I hope it will help others.

* Cookie
* @author Jeremy Simkins <son9ne@gmail.com>
class Cookie {
* The time the cookie expires.
* This is a Unix timestamp so is in number of seconds since the epoch.
* In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire.
* Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days.
* If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
* @var int
private static $expire = 0;

* The path on the server in which the cookie will be available on.
* If set to '/', the cookie will be available within the entire domain.
* If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain.
* The default value is the current directory that the cookie is being set in.
* @var string
private static $path;

* The domain that the cookie is available.
* To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'.
* The . is not required but makes it compatible with more browsers.
* Setting it to www.example.com will make the cookie only available in the www subdomain.
* Refer to tail matching for details (http://curl.haxx.se/...ookie_spec.html).
* @var string
private static $domain;

* Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client.
* When set to TRUE, the cookie will only be set if a secure connection exists.
* On the server-side, it's on the programmer to send this kind of cookie only on secure connection (e.g. with respect to $_SERVER["HTTPS"]).
* @var bool - true || false
private static $secure;

* When TRUE the cookie will be made accessible only through the HTTP protocol.
* This means that the cookie won't be accessible by scripting languages, such as JavaScript.
* This setting can effectively help to reduce identity theft through XSS attacks (although it is not supported by all browsers).
* Added in PHP 5.2.0.
* @var bool - true || false
private static $httponly;

* Initiate the Cookie object and set default values for cookies
* @param string $domain
* @param string $path
* @param bool $secure
* @param bool $httponly
public static function init($domain = '', $path = '/', $secure = false, $httponly = false) {
# Auto set the cookie name from the current domain unless a domain is given
self::$domain = ( $domain ) ? $domain : ( isset( $_SERVER['HTTP_HOST'] ) ? ( ( substr( $_SERVER['HTTP_HOST'], 0, 4 ) == 'www.' ) ? substr( $_SERVER['HTTP_HOST'], 3 ) : '.' . $_SERVER['HTTP_HOST'] ) : '.weddingbudget.dev' );
self::$path = $path;
self::$secure = $secure;
self::$httponly = $httponly;

* Sets a Cookie
* @param string $name
* @param mixed $value
* @param bool $force - Force the Cookie to set for use on the same page (instead of next loading)
* @param int $expire - Set the cookie expiration (Defaults to user closes browser)
* @return bool
public static function set($name, $value = '', $force = false, $expire = NULL) {
* Fix common pitfalls
# Cookie value (A false value will delete the cookie, this will force the value as an int)
if ( $value === true || $value === false ) {
$value = (int) $value;

# Set the cookie value
if ( $value ) {
$value = base64_encode( serialize( $value ) );

# Check cookie size
if ( strlen( $value ) > ( 4 * 1024 ) ) {
trigger_error( "The cookie {$name} exceeds the specification for the maximum cookie size. Some data may be lost", E_USER_WARNING );

# Force value into superglobal
if ( $force ) {
$_COOKIE[$name] = $value;

# Set the cookie
return setcookie( $name, $value, ( ( $expire ) ? ( time() + (int) $expire ) : self::$expire ), self::$path, self::$domain, self::$secure, self::$httponly );

* Checks is a cookie exist
* @param string $name
public static function exist($name) {
return isset( $_COOKIE[$name] );

* Fetch a Cookie value
* @param string $name
* @return mixed
public static function fetch($name) {
return ( isset( $_COOKIE[$name] ) ) ? unserialize( base64_decode( $_COOKIE[$name] ) ) : NULL;

* Removes a Cookie
* @param string $name
* @param bool $force - Force the cookie to delete (Will removed value from super global)
* @return bool
public static function remove($name, $force = false) {
# Ensure the cookie is set
if ( isset( $_COOKIE[$name] ) ) {

# Remove from superglobal
if ( $force ) {
unset( $_COOKIE[$name] );

# Remove the cookie
return setcookie( $name, '', time() - ( 3600 * 25 ), self::$path, self::$domain, self::$secure, self::$httponly );

in_array not working as expected

13 October 2011 - 05:13 PM

I was under the impression that in_array can search with an array value.
I noticed that it does not work for the following code:
$array1 = array(1, 2);
$array2 = array(1, 2, 3, 4, 5);

echo in_array($array1, $array2) ? 'Found' : 'Lost';

Is this expected behavior? If so can you help me better understand why? (perhaps I am just tired from working all day and it's obvious)
I am trying to identify if an array contains any of the values from the given search array.

I read the in_array manual an it shows an example with a multidimensional array but not a simple array.

Would it just be more efficient to loop over the search array and manually check the values? (This is what I am about to resort to)

Thanks for any help on the matter or just fixing my stupid.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download