Tag Archives: PHP

Fix associate-o-matic images not showing

After moving a clients Associate-o-matic store to a new hosting, images have stopped showing. If we attempted to view the image the following error would appear:

Warning: file_get_contents() [function.file-get-contents]:… File(/aom/img.php) is not within the allowed path(s)

Even after updating to the new version of AOM I could not get it  to work. The work around I found is to use cURL intead of file_get_contents();  To do this I followed these simple steps.

  1. Download and open file /aom/img.php
  2. copy the function CURL replacement for file_get_contents to the end of the file before ?>
  3. comment out the line echo file_get_contents($img); (just add # at the start of the line, do this for both instances of the line)
  4. add echo file_get_contents_curl($img); under both lines you have just commented out.
  5. Save and upload the file.

 

 

 

Technorati Tags: , , , ,

Cardsave error “transaction date/time expired”

If you are using CardSave (UK Version) and you come across the following error:

This transaction cannot be processed. It was rejected because the passed transaction date/time has expired. Please press “Back” in your browser and resubmit the transaction.”

It’s caused by your server providing a different timezone to your CardSave Gateway. You need to setup your server/script time zone to UTC.  In PHP you can do this by simply adding this line to your script:  date_default_timezone_set(‘UTC’);

For example, I was having a problem with the Cardsave(hosted) payment extension for OpenCart.  If you are having the same problem do this:

  1. Open the file /catalog/controler/payment/cardsave_hosted.php
  2. Find this line  $this->data[‘fields’][‘TransactionDateTime’] = (date(“Y-m-d H:i:s”).  ‘ +00:00’);  (line 305 I think)
  3. Just before that line add this :  date_default_timezone_set(‘UTC’); 
  4. Upload file to server and you are sorted.

Technorati Tags: , , , , , ,

It is not safe to rely on the system’s timezone settings

Recently I have been having the following error on my PHP code every time I call the PHP function date();  Mostly when running it on my local test server.

Warning: date(): It is not safe to rely on the system’s timezone settings

Cause: Since PHP5.1.0 the E_RESTRICT setting causes PHP to report error for every call
to a date/time function, if no default time is set.

Fix:
There are 2 approaches to  resolving this.

  1. Set time setting to your PHP script with the function date_default_timezone_set();  with the intended time zone/location eg: for GMT one can use date_default_timezone_set(‘Europe/London’);
  2. Set time setting to your php.ini file by editing the line ;date.timezone = to date.timezone = “Europe/London” or you required location. This is good for setting a server wide time setting.

Technorati Tags: , , , , ,

Automatically display form data with PHP

This is a simple PHP  script to automatically display (dump output)  data submited from a html form.

The form setup

  • all inputs (form fields) need to have the same name with [] at the end to turn it into an array,  e.g <input type=text name=formdata[]>

formq.html content

<form method=post action=showme.php>
Name: <input type=text name=formdata[]><br>
Email: <input type=text name=formdata[]><br>

<input type=submit value=ok>
</form>

The Script setup

showme.php content

<?php
$data = $_POST[‘formdata’]; # get value from the form fields

foreach ( $data as $key => $value ) { # loop through array collecting the results

echo  “$value<br>”;  # output the data  – print to page
}
?>

Technorati Tags: , , , ,

PDF to Email with registration

Serve PDF files on your website by requesting the user to register their email address. The PDF file is sent to the given email address and the user details registered on a database. This is a very simple script and relies on four main features.

Apache mod_rewrite (via the .htaccess file)

PHPMailer

MySQL database

the simple-register.php script itself

Read more »

Technorati Tags: , , ,