<?php
function die_force_page_to_https()
{
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='off')
{
$u='https://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$t='';
$t.='<html>';
$t.= '<head>';
$t.= '<meta http-equiv="Refresh" content="0;url='.$u.'>';
$t.= '</meta>';
$t.= '</head>';
$t.= '<body>';
$t.= '</body>';
$t.='</html>';
die($t);
}
}
?>
Monday, August 13, 2007
PHP: Force a page to https
Here is some php code which forces a page to redirect to the same page for https at port 443.
Monday, August 06, 2007
APACHE: Problem with mod_rewrite setup
One way to see if mod_rewrite is installed is to create a file called info.php with the following contents
Put the file in your server root and view it at http://localhost/info.php. Go to the apache section and look at Loaded Modules. If you see mod_rewrite listed there, you can start using the mod_rewrite commands. If not, you have to play with the apache config file: http.conf, add the following (a website told me to do this):
... and make sure the mod_rewrite.so file is in the right place. Then restart your web server. (suse linux: "rcapache2 restart", or windows: Control Panel->Administrative Tools->Services, right click on Apache and select restart)
PROBLEM:
Apache fails to restart.
In windows you can discover the reason using the Event Viewer (Control Panel->Administrative Tools->Services->Event Viewer). It gives the error for Apache:
Invalid command 'AddModule', perhaps mis-spelled or defined by a module not included in the server configuration
REASON:
AddModule for mod_rewrite is for apache 1.2 to 1.3x, but not apache2. I was running Apache2, so instead, the following worked for me in the apache config file:
Now restart apache, and check your http://localhost/info.php file and Voila! mod_rewrite is there, listed as a Loaded Module.
Now as for how to actually use mod_rewrite there are a lot of examples out there,
thats what google is for, right?
http://hypermail.linklord.com/new-httpd.old/2001/Jul/0863.html
<?php echo phpinfo(); ?>
Put the file in your server root and view it at http://localhost/info.php. Go to the apache section and look at Loaded Modules. If you see mod_rewrite listed there, you can start using the mod_rewrite commands. If not, you have to play with the apache config file: http.conf, add the following (a website told me to do this):
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c
... and make sure the mod_rewrite.so file is in the right place. Then restart your web server. (suse linux: "rcapache2 restart", or windows: Control Panel->Administrative Tools->Services, right click on Apache and select restart)
PROBLEM:
Apache fails to restart.
In windows you can discover the reason using the Event Viewer (Control Panel->Administrative Tools->Services->Event Viewer). It gives the error for Apache:
Invalid command 'AddModule', perhaps mis-spelled or defined by a module not included in the server configuration
REASON:
AddModule for mod_rewrite is for apache 1.2 to 1.3x, but not apache2. I was running Apache2, so instead, the following worked for me in the apache config file:
LoadModule rewrite_module modules/mod_rewrite.so
Now restart apache, and check your http://localhost/info.php file and Voila! mod_rewrite is there, listed as a Loaded Module.
Now as for how to actually use mod_rewrite there are a lot of examples out there,
thats what google is for, right?
http://hypermail.linklord.com/new-httpd.old/2001/Jul/0863.html
Friday, August 03, 2007
CSS: Irritating IE FORM tags act like BR tag
One of the irritating things about IE is that the form start tag is automatically treated like a line-break tag.
Add this to your stylesheet to solve the problem:
source(s): http://weblogs.macromedia.com/cantrell/archives/2003/05/
git_rid_of_anno.cfm
Add this to your stylesheet to solve the problem:
form {margin: 0px 0px 0px 0px; }
source(s): http://weblogs.macromedia.com/cantrell/archives/2003/05/
git_rid_of_anno.cfm
Wednesday, August 01, 2007
C++: Set Registry Key Values
This piece of example code writes a key to the windows registry.
source(s): http://msdn2.microsoft.com/en-us/library/ms724923.aspx
http://msdn2.microsoft.com/en-us/library/ms724875.aspx
#include <windows.h>
int SetRegValue(char *key_name,char *key_word,char *b,int dwType,int s)
{
int j=0;
DWORD lpdwDisposition;
HKEY hKey;
j=RegCreateKeyEx(
HKEY_CURRENT_USER,
key_name,
0, /* reserved */
NULL, /* address of class string */
REG_OPTION_NON_VOLATILE, /* special options flag */
KEY_WRITE, /* desired security access */
NULL, /* address of key security structure */
&hKey, /* address of buffer for opened handle */
&lpdwDisposition /* address of disposition value buffer */
);
if (j==ERROR_SUCCESS)
{
RegSetValueEx(hKey, key_word, 0, dwType, (unsigned char *)b, s);
RegCloseKey(hKey);
}
return(j);
}
int main(int argc, char* argv[])
{
char val[100]="myusername";
SetRegValue("Software\\MySoft\\Settings","Username", val, REG_SZ, 100);
return 0;
}
source(s): http://msdn2.microsoft.com/en-us/library/ms724923.aspx
http://msdn2.microsoft.com/en-us/library/ms724875.aspx
Subscribe to:
Posts (Atom)