Latest Post

Error: No input file specified.

While trying to run a codeigniter app the other day I came across this error just after I had finished uploading the files and making the ne...

Wednesday, November 30, 2011

Force SSL/https using .htaccess and mod_rewrite

I recently had to update a client's website to force the use of https on their site initially they wanted it for just a subsection of the website and then later on they decided they wanted it for the whole site. Fortunately i found this useful htaccess/mod_rewrite tip off the web fairly quickly.

1. For a subsection of the website (assuming this is in its own folder) use the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]


be sure to place the htaccess file inside the respective subfolder

2. For the whole website, use the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]


make sure to place the htaccess file in the website's root folder

Hope this helps someone as it did me. :)

Till next time, happy coding.

Friday, October 21, 2011

Calling a php script from within java

Recently i worked on a project that required me to modify an existing java app inline with changes in the API through which the java system communicated with a service provider's business logic.

After weeks of trying to get the Java to communicate with the new web service, and not wanting to change anything else inside the java program except the web service client bit, which i could get to work (due to issues i did not have time to further investigate :)). I therefore decided to write the client in PHP, using NuSoap, and then simply call the NuSoap client from within java which worked out much easier than i expected.

All i needed from the client was the response XML, which would then be handled using preexisting java code so below is extracts from the java program.

[CODE]
try
{
URL phpClient = new URL("my php url here");


try{

URLConnection yc = phpClient.openConnection();

BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));

String inputLine;
Integer count = 1;
while ((inputLine = in.readLine()) != null) {
this.result += inputLine;
}

in.close();
} catch(IOException e){
System.out.println(" web php/service error " + e.toString());
}
} catch(MalformedURLException nameOfTheException){
//
}
[/CODE]

Monday, February 28, 2011

Deleting Duplicate Rows in a MySQL Database

Assuming the following bad table design:
CREATE TABLE bad_table2 (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
name VARCHAR(20) NOT NULL
);

INSERT INTO bad_table2(id,name) VALUES
(1,'Things Fall Apart'),
(2,'Things Fall Apart'),
(3,'The Famished Road'),
(4,'Things Fall Apart'),
(5,'The Famished Road'),
(6,'Thirteen cents'),
(7,'Thirteen cents');

I can remove duplicates easily with the following line:
alter ignore table bad_table2 add unique index `unique_index` (name);

And then remove the added index.
alter table bad_table2 drop index `unique_index`;

Source: Comment by Paul Swarthout @ databasejournal.com

Monday, February 7, 2011

Enable Classic ASP custom error pages

After days of searching the web and nagging my host i finally came across this piece of code from here

It was just what i needed to show classic ASP custom error pages using the config file

<?xml version="1.0" encoding="UTF-8"?><configuration> <system.webServer> <httpErrors> <remove statusCode="500" subStatusCode="100" /> <error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/error-500.asp" responseMode="ExecuteURL" /> </httpErrors> </system.webServer></configuration>

Wednesday, February 2, 2011

Javascript: reversing a string


function strrev(str)
{
if (!str) return '';
var revstr='';
for (i = str.length-1; i>=0; i--)
revstr+=str.charAt(i)
return revstr;
}

alert(strrev("Hello World!"));


OR alternatively you can use split("") to
convert a string to an array, reverse() to
reverse the array, and join("") to convert
it back.

function strrev(str)
{
return str.split("").reverse().join("");
}

alert(strrev("Hello World!"));

Chitika Ads