How can I properly URL encode a string in PHP?

For the URI query use urlencode/urldecode; for anything else use rawurlencode/rawurldecode. The difference between urlencode and rawurlencode is that urlencode encodes according to application/x-www-form-urlencoded (space is encoded with +) while rawurlencode encodes according to the plain Percent-Encoding (space is encoded with %20).

C2DM implementation PHP code

To register your own server system and obtain the Authorise Tokens (this is what Cpt. Ohlund proposed): function googleAuthenticate($username, $password, $source=”Company-AppName-Version”, $service=”ac2dm”) { session_start(); if( isset($_SESSION[‘google_auth_id’]) && $_SESSION[‘google_auth_id’] != null) return $_SESSION[‘google_auth_id’]; // get an authorization token $ch = curl_init(); if(!ch){ return false; } curl_setopt($ch, CURLOPT_URL, “https://www.google.com/accounts/ClientLogin”); $post_fields = “accountType=” . urlencode(‘HOSTED_OR_GOOGLE’) . “&Email=” . … Read more

How to ceil, floor and round bcmath numbers?

After a night lost trying to solve this problem I believe I’ve found a rather simple solution, here it is: function bcceil($number) { if (strpos($number, ‘.’) !== false) { if (preg_match(“~\.[0]+$~”, $number)) { return bcround($number, 0); } if ($number[0] != ‘-‘) { return bcadd($number, 1, 0); } return bcsub($number, 0, 0); } return $number; } … Read more

How to place two forms on the same page?

You could make two forms with 2 different actions <form action=”login.php” method=”post”> <input type=”text” name=”user”> <input type=”password” name=”password”> <input type=”submit” value=”Login”> </form> <br /> <form action=”register.php” method=”post”> <input type=”text” name=”user”> <input type=”password” name=”password”> <input type=”submit” value=”Register”> </form> Or do this <form action=”doStuff.php” method=”post”> <input type=”text” name=”user”> <input type=”password” name=”password”> <input type=”hidden” name=”action” value=”login”> <input type=”submit” … Read more

PHP: How To Disable Dangerous Functions

Afraid you’re pretty much stuck using php.ini to disable most of those. However, it gets worse. eval() is technically not a function, it is a language construct, so it CANNOT be disabled using disable_functions. In order to do that, you would have to install something like Suhosin and disable it from there. A good webmaster … Read more

What is PHP session_start()

The PHP session system lets you store securely data in the $_SESSION global array. A typical example is to store the user’s identifier in the session when they type in their password: if ($user = try_login($login, $password)) $_SESSION[‘user’] = $user; Then, you can access that information on all other pages: if (isset($_SESSION[‘user’])) // logged in … Read more

.htaccess for cakephp

The answer is that there are 3 different .htaccess files: /var/www/app/webroot/.htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] </IfModule> /var/www/app/.htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] </IfModule> /var/www/.htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule> It’s … Read more