Category Archives: amp

HTTP-like treatment for custom URI scheme, possible?

I defined a new URI scheme on my Windows system (following this thread: how do I create my own URL protocol? (e.g. so://...))

I want the custom URI protocol to act like HTTP within Chrome/Firefox...

That is, I want: myprotocol://localhost/test.html

to act exactly like: http://localhost/test.html

Is it possible, or does the browser insist on valid URI schemes, even if they are fully defined in the registry?

(This pertains to a local server and is required for personal application testing; I realise custom URI's are a bad standard and should not be used in production)

403 Forbidden – Mac Local Host

I am attempting to set up an AMP stack in order to do some basic web design with HTML 5, PHP, CSS, Apache, etc. I have done this on a PC but I am having trouble setting it up on my new Mac. I am trying to follow these steps (http://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-osx-10-11-el-capitan/) but at the end of the first set of instructions I can't get the files to show and am getting a 403 error. Can someone please point me in the right direction or give me a good resource. Thank you.

Here is my current permissions on the file:

total 16
-rw-r--r--  1 root  wheel   96 Jan 10 13:39 Guest.conf
-rw-r--r--  1 root  wheel  132 Jan 20 15:52 username.conf

403 Forbidden – Mac Local Host

I am attempting to set up an AMP stack in order to do some basic web design with HTML 5, PHP, CSS, Apache, etc. I have done this on a PC but I am having trouble setting it up on my new Mac. I am trying to follow these steps (http://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-osx-10-11-el-capitan/) but at the end of the first set of instructions I can't get the files to show and am getting a 403 error. Can someone please point me in the right direction or give me a good resource. Thank you.

Here is my current permissions on the file:

total 16
-rw-r--r--  1 root  wheel   96 Jan 10 13:39 Guest.conf
-rw-r--r--  1 root  wheel  132 Jan 20 15:52 username.conf

AMP wordpress plugin and detecting mobile device via .htaccess

I've setup an AMP version of my website and have tested it via the browser and it's working ok using the AMP wordpress plugin. I then went to add some code to my .htaccess file to detect mobile devices and rewite to the /amp/ version. Please advise if I have a mistake in my .htacess code as I can't get mobile devices to detect my amp version.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

#AMP Rewrite
RewriteCond %{REQUEST_URI} !/amp$ [NC]
RewriteCond %{HTTP_USER_AGENT} (android|blackberry|googlebot\-mobile|iemobile|iphone|ipod|\#opera\ mobile|palmos|webos) [NC]
RewriteRule ^([a-zA-Z0-9-]+)([\/]*)$ http://www.example.com/$1/amp/ [L,R=302]
</IfModule>

How to remove reference to ttf file after using imagettftext?

I'm currently developing a captcha system for the site I'm currently developing for a school project.. here: http://rjtestsystem.atwebpages.com/

Here's the code, err, prototype I came up with so far:

 <?php
    if (isset($_GET['METHOD']) && $_GET['METHOD']=='captcha')
    {   session_start();
        $code=rand(1000,9999);
        $_SESSION["code"] = $code;
        session_write_close();
        $font = rand(1,4).".ttf";
        if ($font == "1.ttf")
            $font_size = 20;
        else if ($font == "2.ttf")
            $font_size = 25;
        else if ($font == "3.ttf")
            $font_size = 30;
        else if ($font == "4.ttf")
            $font_size = 35;
        $angle = 0;
        $width = 120;
        $height = 60;
        $bounding_box = imagettfbbox($font_size, $angle, $font, $code);
        $textwidth = abs($bounding_box[4] - $bounding_box[0]);
        $textheight = abs($bounding_box[5] - $bounding_box[1]);
        $x = ($width - $textwidth) / 2;
        $y = (($height*3/4) + $textheight) / 2;
        $image = imagecreatetruecolor($width, $height);
        $text_background = imagecolorallocate($image, 0, 0, 0);
        $color = imagecolorallocate($image, 230, 230, 230);
        imagefill($image, 0, 0, $text_background);
        imageline($image, 0, $y-rand(0,10), $width, $y-rand(0,10), $color);
        imageline($image, 0, $y, $width, $y, $color);
        imageline($image, 0, $y+rand(0,10), $width, $y-rand(0,20), $color);
        imageline($image, $x+rand(0,$width/2), 0, $x+rand($width/2,$width), $height, $color);
        imageline($image, $x+rand(0,$width/2), $height, $x+rand($width/2,$width), 0, $color);
        for($i=0;$i<400;$i++)
        {   imagesetpixel($image,rand()%$width,rand()%$height,$color);
        }
        imagettftext($image, $font_size, $angle, $x, $y, $color, $font, $code);
        header("Cache-Control: no-cache, must-revalidate");
        header('Content-type: image/png');
        imagepng($image);
        imagedestroy($image);
        exit();
    }
    ?>
    <img src = "<?php echo $_SERVER['PHP_SELF']; ?>?METHOD=captcha">

The code seems to be working fine, but when I try to move the files elsewhere, the system would give me a message that the file is being used by another program. It seems that the references to the TTF files are still there even after executing the code. I've tried to look for a way to stop this behavior but I can't seem to get my searches right. Well, the problem goes away once I restart the server, but it's a hassle when debugging. Is there a way or proper method to remove the references / file handle / etc to the TTF files or close this process as soon as it's finished? If possible, I'd like to keep using this code.

I have only a year of experience in Php so please bear with my rudimentary way of coding and asking questions. If anyone can lead me to the right discussions, please do. Thank you.

I'm using WAMP server version 2.4.

How to remove reference to ttf file after using imagettftext?

I'm currently developing a captcha system for the site I'm currently developing for a school project.. here: http://rjtestsystem.atwebpages.com/

Here's the code, err, prototype I came up with so far:

 <?php
    if (isset($_GET['METHOD']) && $_GET['METHOD']=='captcha')
    {   session_start();
        $code=rand(1000,9999);
        $_SESSION["code"] = $code;
        session_write_close();
        $font = rand(1,4).".ttf";
        if ($font == "1.ttf")
            $font_size = 20;
        else if ($font == "2.ttf")
            $font_size = 25;
        else if ($font == "3.ttf")
            $font_size = 30;
        else if ($font == "4.ttf")
            $font_size = 35;
        $angle = 0;
        $width = 120;
        $height = 60;
        $bounding_box = imagettfbbox($font_size, $angle, $font, $code);
        $textwidth = abs($bounding_box[4] - $bounding_box[0]);
        $textheight = abs($bounding_box[5] - $bounding_box[1]);
        $x = ($width - $textwidth) / 2;
        $y = (($height*3/4) + $textheight) / 2;
        $image = imagecreatetruecolor($width, $height);
        $text_background = imagecolorallocate($image, 0, 0, 0);
        $color = imagecolorallocate($image, 230, 230, 230);
        imagefill($image, 0, 0, $text_background);
        imageline($image, 0, $y-rand(0,10), $width, $y-rand(0,10), $color);
        imageline($image, 0, $y, $width, $y, $color);
        imageline($image, 0, $y+rand(0,10), $width, $y-rand(0,20), $color);
        imageline($image, $x+rand(0,$width/2), 0, $x+rand($width/2,$width), $height, $color);
        imageline($image, $x+rand(0,$width/2), $height, $x+rand($width/2,$width), 0, $color);
        for($i=0;$i<400;$i++)
        {   imagesetpixel($image,rand()%$width,rand()%$height,$color);
        }
        imagettftext($image, $font_size, $angle, $x, $y, $color, $font, $code);
        header("Cache-Control: no-cache, must-revalidate");
        header('Content-type: image/png');
        imagepng($image);
        imagedestroy($image);
        exit();
    }
    ?>
    <img src = "<?php echo $_SERVER['PHP_SELF']; ?>?METHOD=captcha">

The code seems to be working fine, but when I try to move the files elsewhere, the system would give me a message that the file is being used by another program. It seems that the references to the TTF files are still there even after executing the code. I've tried to look for a way to stop this behavior but I can't seem to get my searches right. Well, the problem goes away once I restart the server, but it's a hassle when debugging. Is there a way or proper method to remove the references / file handle / etc to the TTF files or close this process as soon as it's finished? If possible, I'd like to keep using this code.

I have only a year of experience in Php so please bear with my rudimentary way of coding and asking questions. If anyone can lead me to the right discussions, please do. Thank you.

I'm using WAMP server version 2.4.