Archive for category PHP code

Declare new array php

You can declare new array in PHP by using the code below:

$new_array = array();

,

No Comments

preg_replace to replace all href

Here’s a good one

$pattern = "/as+hrefs*=s*['\"]?([^'\">]+)['\"]?>([^<]*)</ie";
$replacement = "'a href=\"$1'.strtolower(str_replace(' ', '', '$2')).'\">$2<'";
$string = preg_replace($pattern, $replacement, $string);


The pattern says to find:

  1. ‘a href‘ — there must be at least one space in between the ‘a’ and the ‘href‘ ( \s+ ),
  2. followed by zero or more spaces( \s* ),
  3. followed by the equal sign ( = ),
  4. followed by zero or more spaces ( \s* ),
  5. followed by an optional single quotation mark or double quotation mark ( ['\"]? ),
  6. followed by one or more of anything that is not a single quotation mark, a double quotation mark or an end element marker and capture this subpattern by using parentheses ( ([^'\">]+) ),
  7. followed by an optional closing single quotation mark or double quotation mark ( ['\"]? ),
  8. followed by a closing element marker ( > ),
  9. followed by zero or more of anything that is not an opening element marker ( ([^<]*) ),
  10. followed by an opening element marker.

Taken from http://www.webmasterworld.com/forum88/13008.htm

, , , , , ,

No Comments

Cross-Site Scripting

Here’s a nice tutorial:

http://www.xssed.com/article/6/Paper_Kr3ws_Cross-Site_Scripting_Tutorial/

,

No Comments

Uploading a file using Curl in PHP

Here’s how to upload files using curl in php: (it’s very easy)

notice the @ infront of the file path, this is the magic part.

<?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    // same as <input type="file" name="file_box">
    $post = array(
        "file_box"=>"@/path/to/myfile.jpg",
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $response = curl_exec($ch);
?>

Source: http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html

, , , , , , , , , , , ,

No Comments

Permanet Redirect in PHP

<?php
// Permanent redirection
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://www.website.com/”);
exit();
?>

, , ,

No Comments

Import Mochimedia Feed

Just make a code for importing Mochimedia game feed.

It will import the feed by creating post, add tag, insert into category, and schedule it dailly. It is using wordpress technology. You need to put these files in wp root.

Download it here.

,

No Comments

Get absoute path PHP

<?php
$path = getcwd();
echo $path;
?>

, , , ,

No Comments

Handling Paypal Recurring Payments

* Recurring Payments Demo
* How Recurring Payments Work
* Recurring Payments Terms
* Recurring Payments With Express Checkout
* Options for Creating a Recurring Payments Profile
* Recurring Payments Profile Status
* Getting Recurring Payments Profile Information
* Modifying a Recurring Payments Profile
* Billing the Outstanding Amount of a Profile
* Recurring Payments Notifications

Source from paypal

Additional source: http://articles.techrepublic.com.com/5100-10878_11-5331883.html

For Recurring Payments Notifications, you can use IPN. Merchants are notified of certain events through IPN. For recurring payments profiles created using Express Checkout, buyers are also notified of specific events by email.

To activate the IPN, you need to login to your account and activate it from “Instant Payment Notification Preferences” Menu.

Once payment, subscription started, or subscription ended it will execute the url you entered in IPN setting.

Here are the request from paypal for recurring payment:

Pay

transaction_subject:, payment_date:00:24:20 Jan 29, 2010 PST, txn_type:subscr_payment, subscr_id:I-TR8AEDTYY3A3, last_name:,,
residence_country:ID, payment_gross:0.10, mc_currency:USD, business:myemail@domain.com, payment_type:instant,
protection_eligibility:Ineligible, verify_sign:AwVFRrppcBWp.SbFNfxVhWwgMJq1AzhZhdCLslBXMKqUWPTs7OhhthbB,
payer_status:verified, payer_email:client@domain.com, txn_id:9E184006CH967554N, receiver_email:myemail@domain.com,
first_name:Adri, payer_id:BRF4CDPWN84AC, receiver_id:DVFZ59JCMFVEN,payment_status:Completed,payment_fee:0.10, mc_fee:0.10, mc_gross:0.10, charset:windows-1252, notify_version:2.9,

subscribe

txn_type:subscr_signup, subscr_id:I-TR8AEDTYY3A3, last_name:,, residence_country:ID, mc_currency:USD,
business:myemail@domain.com, amount3:0.10, recurring:1, verify_sign:A8s9ZB.gPMzpWoypvEK3Oi8kH04SA6rxIBluaeZfMSHesjkeOATMaJRe,
payer_status:verified, payer_email:client@domain.com, first_name:Adri, receiver_email:myemail@domain.com, payer_id:BRF4CDPWN84AC, reattempt:1, subscr_date:00:24:19 Jan 29, 2010 PST, charset:windows-1252, notify_version:2.9, period3:1 M, mc_amount3:0.10,

cancel

txn_type:subscr_cancel, subscr_id:I-TR8AEDTYY3A3, last_name:,, residence_country:ID, mc_currency:USD, business:myemail@domain.com, amount3:0.10, recurring:1, verify_sign:AwLeRoV0CcJ4bqIPyyj4pN2QzIoEA1eWFEwodSF46c0b-.d2eIQHFjiE,
payer_status:verified, payer_email:client@domain.com, first_name:Adri, receiver_email:myemail@domain.com,
payer_id:BRF4CDPWN84AC, reattempt:1, subscr_date:00:24:19 Jan 29, 2010 PST, charset:windows-1252, notify_version:2.9, period3:1 M, mc_amount3:0.10,

There are two variable you need to check txn_type and subscr_id.

You can see that txn_type can be subscr_payment, subscr_signup, and subscr_cancel

, , , , , , , , , , , , , , , , , , , , , , , , , ,

No Comments