Monday, July 1, 2013

Forcing some urls to HTTPS and some on HTTP using cakephp

Hi guys, today I was trying to do this task and did a lot of R&D. Tried some httaccess rules, tried cakephp routers and most specially which did my half work ( forcing some urls to https ) is security component of cakephp. But non of these components and techniques worked well like I wanted to do it. Then I wrote a simple function and it worked well.

Here is I am gonna show you how to redirect some urls like checkout, login, register on HTTPS and vice virsa. Here is that function,





/*

    redicting some urls to https

    */

    function securityrules()

    {

        $arrparams = $this->params;

        

        if( $_SERVER["HTTPS"] == "on" )

        {

            if( $arrparams['action'] != "login" && $arrparams['action'] != "register" && $arrparams['action'] != "reset" )

            {

                $this->redirect('http://' . env('SERVER_NAME') . $this->here);

            }

        }

        else

        {

            if( $arrparams['action'] == "login" || $arrparams['action'] == "register" || $arrparams['action'] == "reset" )

            {

                $this->redirect('https://' . env('SERVER_NAME') . $this->here);

            }

        }

    }


And for using it place this function in AppController.php and call it at the start of beforeFilter() function And enjoy. Don't waste your time on other stupid techniques like i wasted my whole day :( Thanks

Friday, November 30, 2012

Number of Users Online script in PHP

Sometime our clients demand for showing how many visitors are online currently on their website. This can be done by many ways. I am going to illustrate two methods of doing this. One is file based and other one is database based. Let us see how to achieve this by both methods one by one.

1) File Based Method:

In this method PHP script writes online visitors information in a text file. That text file is updated after a specific interval of time and script reads that file and show a counter of online visitors where required. Let us see the details of this method step by step,

Step 1) First of all you have to create a .txt file and place it on any folder in your server. In my case I am creating this file on root folder of my website and naming it ip.txt. After updating this file by code, it looks something like this,

127.0.0.1****1354262381++++
127.0.0.1****1354262381++++
127.0.0.1****1354262381++++

Step 2):Then copy and paste the code below where you want to show that counter,

<php
    $url = $_SERVER['SCRIPT_FILENAME'];
    $pp = strrpos($url,"/");
    $url = substr($url,0,$pp);
    $ura = $_SERVER['SCRIPT_NAME'];
    $host = $_SERVER['SERVER_NAME'];
    $ser = "http://$host";
    $ura= $ser.$ura; 
    $pp1 = strrpos($ura,"/");
    $ura = substr($ura,0,$pp1);
    $url1=explode('/', $url);
    $url=array_pop($url1);
    $url1=implode('/', $url1);
    $ura1=explode('/', $ura);
    $ura=array_pop($ura1);
    $ura1=implode('/', $ura1);

    $hm = "$url1"; 
    $hm2 = "$ura1"; 
    include "onlinevisitors.php";
?>


Step 3):  Next step is to create a file named onlinevisitors.php file and place in the folder where you included it in above code. In our case root folder,


<?php
$rip = $_SERVER['REMOTE_ADDR'];
$sd  = time();
$count = 1;

$file1 = "ip.txt";
$lines = file($file1);
$line2 = "";

foreach ($lines as $line_num => $line)
{
 //echo $line."";
 $fp = strpos($line,'****');
 $nam = substr($line,0,$fp);
 $sp = strpos($line,'++++');
 $val = substr($line,$fp+4,$sp-($fp+4));
 $diff = $sd-$val;
 if($diff < 300 && $nam != $rip)
 {
  $count = $count+1;
  $line2 = $line2.$line;
  //echo $line2;
 }
}

$my = $rip."****".$sd."++++\n";
$open1 = fopen($file1, "w");
fwrite($open1,"$line2");
fwrite($open1,"$my");
fclose($open1);

echo "<table width=180 height=30 bgcolor=#fdfdfd style=\"border: 1px green solid;\"><tr><td align=left valign=top>";
echo "</td><td align=center>";
echo "<span style=\"font-family: verdana,arial,helvetica; font-size: 11px; font-weight: bold; color: #aaccaa;\">";
echo "Total users online - <font color=red>$count</font></span><br>";
echo "</td></tr></table>";
?>

2) Database Driven Method:

comming soon...

Wednesday, November 14, 2012

Which Web Programming language to learn to keep you employed?

There are thousands of programming languages out there and have their own value over one and other. But there are a few programming languages which can keep you employed and you don't have to worry about earnings. Learning a right programming language on right time and right place is very necessary for your carrier. There are many examples out there who are not happy with their field and struggling in the market due to this fact. That's why I am going to share with my blog readers about the best programming languages and their scope in different areas of the world.
  • PHP
  • MySQL
  • Javascript
  • Perl
  • Ruby
  • Python
  • ASP.net

Tuesday, November 13, 2012

How to increase PTCL EVO signals

PTCL EVO is one of the best source of wireless internet connectivity and it offers coverage in more than 250 cities in pakistan nationwide. But sometimes eVo customers are returning their devices within 3 days because of dis-satisfaction or no signals at there homes or offices. So i thought there should be some method to strengthen the eVo signals so that customers can enjoy the great internet service out there.

Friday, November 9, 2012

What is radiotherapy treatment?

As x-Rays have been discovered almost 10 years ago and these are being used in medical science. These are used for the diagnosis purpose as well as for the treatment such as radiotherapy. There are two types of radiotherapy,

1. External radiotherapy

2. Internal radiotherapy

External radiotherapy is for external body and internal radiotherapy is used for internal body parts. Radiotherapy is actually used to distroye cancel cells but it may damage normal cells as well. But fortunately normal cells can repair themselves later on.