A PHP Error was encountered

Severity: Warning

Message: Undefined variable $page

Filename: front/Articles.php

Line Number: 91

Backtrace:

File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 91
Function: _error_handler

File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Undefined variable $pages

Filename: front/Articles.php

Line Number: 110

Backtrace:

File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 110
Function: _error_handler

File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Undefined variable $page

Filename: front/Articles.php

Line Number: 111

Backtrace:

File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 111
Function: _error_handler

File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Undefined variable $category

Filename: front/Articles.php

Line Number: 113

Backtrace:

File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 113
Function: _error_handler

File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Undefined variable $articles

Filename: front/Articles.php

Line Number: 114

Backtrace:

File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
Line: 114
Function: _error_handler

File: /opt/bitnami/projects/celticproductions.net/index.php
Line: 315
Function: require_once

Secure file_get_contents PHP function | Celtic Productions IT

Secure file_get_contents PHP function

  • Home
  • /
  • Technical Articles
  • A PHP Error was encountered

    Severity: Warning

    Message: Trying to access array offset on null

    Filename: front/article.php

    Line Number: 35

    Backtrace:

    File: /opt/bitnami/projects/celticproductions.net/application/views/front/article.php
    Line: 35
    Function: _error_handler

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 124
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 117
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/index.php
    Line: 315
    Function: require_once

  • /
  • Secure file_get_contents PHP function
on 19th November
  • php
  • file_get_contents
  • secure
  • password protected
  • authorization basic
This crops up all the time. We install a particular software suite on a clients' server and when we execute the script, it spits out an error about file_get_contents not expecting some arguments. Grrr, that's our first warning sign that we're probably running PHP4 on the server. A lot of companies continue to run PHP4 and while the upgrade from PHP4 to PHP5 is generally very smooth, not all server components update as well. Thus, rather than upgrading the entire server, we provide some simple bridging functions for some of the most commonly used PHP5 functions. file_get_contents is one such function.

A really handy feature added in PHP 5.0.0 was the concept of context support. A stream context can be very handy for defining such things as authorisation tokens. There is no in-built support for stream contexts within PHP 4 so we provide the following function to our clients and a small wrapper function to decide what to do depending on our environment. Here's file_get_contents_secure:


function file_get_contents_secure($url, $username, $password)
{
$opts = array('http'=>
array('method'=>'POST',
'header'=>sprintf("Authorization Basic %s\r\n",
base64_encode($username.':'.$password)).
"Content-type: application/x-www-form-urlencoded\r\n"
)
);
$context = stream_context_create($opts);
$fh = fopen($url, 'r', false, $context);
ob_start();
fpassthru($fh);
fclose($fh);
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}


That's it, it's really straightforward to call this function:


print file_get_contents_secure('https://mysite.com/secureurl/',
'myusername',
'mypass');


This is a really handy function that you can utilise if you are being forced to run off a PHP 4 server. We're presented with this task quite frequently and I'm sure you're no different.

As with all articles on Celtic Productions, this article is protected by international copyright laws. It may be linked to (we are of course most grateful of links to our articles), however, it may never be reproduced without the prior express permission of its owners, Celtic Productions.
  • A PHP Error was encountered

    Severity: Warning

    Message: Undefined array key "category"

    Filename: core/MY_Controller.php

    Line Number: 94

    Backtrace:

    File: /opt/bitnami/projects/celticproductions.net/application/core/MY_Controller.php
    Line: 94
    Function: _error_handler

    File: /opt/bitnami/projects/celticproductions.net/application/helpers/general_helper.php
    Line: 16
    Function: get_link_for_article

    File: /opt/bitnami/projects/celticproductions.net/application/views/front/article.php
    Line: 241
    Function: get_link_for_article

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 124
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 117
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/index.php
    Line: 315
    Function: require_once

    /articles/18//enabling-gzip-compression-on-your-website.html" class="c-title"> Enabling Gzip compression on your website
    19th November
  • A PHP Error was encountered

    Severity: Warning

    Message: Undefined array key "category"

    Filename: core/MY_Controller.php

    Line Number: 94

    Backtrace:

    File: /opt/bitnami/projects/celticproductions.net/application/core/MY_Controller.php
    Line: 94
    Function: _error_handler

    File: /opt/bitnami/projects/celticproductions.net/application/helpers/general_helper.php
    Line: 16
    Function: get_link_for_article

    File: /opt/bitnami/projects/celticproductions.net/application/views/front/article.php
    Line: 258
    Function: get_link_for_article

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 124
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 117
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/index.php
    Line: 315
    Function: require_once

    /articles/12//file-path-and-name-with-spaces-in-batch-file-for-loop.html" class="c-title"> File path and name with spaces in batch file for loop
    7th October
  • A PHP Error was encountered

    Severity: Warning

    Message: Undefined array key "category"

    Filename: core/MY_Controller.php

    Line Number: 94

    Backtrace:

    File: /opt/bitnami/projects/celticproductions.net/application/core/MY_Controller.php
    Line: 94
    Function: _error_handler

    File: /opt/bitnami/projects/celticproductions.net/application/helpers/general_helper.php
    Line: 16
    Function: get_link_for_article

    File: /opt/bitnami/projects/celticproductions.net/application/views/front/article.php
    Line: 258
    Function: get_link_for_article

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 124
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 117
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/index.php
    Line: 315
    Function: require_once

    /articles/11//add-floating-point-numbers-in-batch-file.html" class="c-title"> Add floating point numbers in batch file
    7th October
  • A PHP Error was encountered

    Severity: Warning

    Message: Undefined array key "category"

    Filename: core/MY_Controller.php

    Line Number: 94

    Backtrace:

    File: /opt/bitnami/projects/celticproductions.net/application/core/MY_Controller.php
    Line: 94
    Function: _error_handler

    File: /opt/bitnami/projects/celticproductions.net/application/helpers/general_helper.php
    Line: 16
    Function: get_link_for_article

    File: /opt/bitnami/projects/celticproductions.net/application/views/front/article.php
    Line: 258
    Function: get_link_for_article

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 124
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/application/controllers/front/Articles.php
    Line: 117
    Function: view

    File: /opt/bitnami/projects/celticproductions.net/index.php
    Line: 315
    Function: require_once

    /articles/2//remote-server-backup--ncftp-.html" class="c-title"> Remote Server Backup (ncftp)
    28th March