Solved

How to: PHP get input tag with name="encypted"

Posted on 2014-02-02
8
417 Views
Last Modified: 2014-02-03
Hi,

I have this bit of code:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <table>
        <tbody><tr><td><input type="hidden" name="on0"></td></tr>
        <tr><td><input type="hidden" name="os0" value="option_0"></td>
        </tr><tr><td></td><td>Number of payments 3</td></tr>
        <tr><td></td><td>Start payments At Checkout</td></tr><tr><td></td><td><table><tbody><tr><th align="LEFT">Due*</th><th align="LEFT">Amount</th></tr>
        <tr><td>Every 1 Month (x 3)</td><td align="right">$897.00 USD</td></tr>
        <tr><td></td><td colspan="2" align="right">Total  $2,691.00 USD</td></tr></tbody></table>
        </td></tr><tr><td colspan="3"><i>*We calculate payments from the date of checkout.<i></i></i></td></tr>
        </tbody></table>
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIIQQYJKoZIhvcNAQcEoIIIMjCCCC4CAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQ=-----END PKCS7-----
">
    <table><tbody><tr><td align="center"><i>Sign up for</i></td></tr><tr><td><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_installment_plan_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" style="border: 0px;"></td></tr></tbody></table>
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Open in new window


I want to use PHP to extract the <input /> tag where name="encrypted". I think it's easier in jQuery but I'm trying to find out how to do this with PHP.

The other question I had to was how do I change the src="https://www.paypalobjects.com/en_US/i/btn/btn_installment_plan_LG.gif" to some other gif I have on my server?

Thanks,
Victor
0
Comment
Question by:Victor Kimura
  • 4
  • 3
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39828310
Are you asking how to do this in the browser? You can't do this in the browser with PHP.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39828320
PHP is used to generate the HTML document, so if this is something that is part of your HTML from a PHP script on your server, you already have the value in the HTML.  The form is submitted to PayPal by HTML on the client machine.  Some additional info here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

As far as changing the image, just change the src= attribute of the tag.  Easy!
0
 

Author Comment

by:Victor Kimura
ID: 39828354
@Cathal. No, it's PHP. PHP is server based.

@Ray
I get that from an ajax callback. So I get that in a PHP variable first based off of a curl call to Paypal. So I can manipulate that form. I just need only the essentials returned since it's a custom shopping cart.

All the buttons are dynamic based on what the user selects and then .ajax() is called and then from the server using PHP I call curl() and then I get some returned variables from Paypal and that's one of the variable values (the <form>) I get back.

So how I can extract this information. Some sample code would help me. =)
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39828391
You make a cURL call to paypal and get an HTML string back?  Try printing it out!  You will want to use "view source" to look at it.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Victor Kimura
ID: 39828759
@Ray, yeah, I did. =) It's in the first post. Posting it again.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <table>
        <tbody><tr><td><input type="hidden" name="on0"></td></tr>
        <tr><td><input type="hidden" name="os0" value="option_0"></td>
        </tr><tr><td></td><td>Number of payments 3</td></tr>
        <tr><td></td><td>Start payments At Checkout</td></tr><tr><td></td><td><table><tbody><tr><th align="LEFT">Due*</th><th align="LEFT">Amount</th></tr>
        <tr><td>Every 1 Month (x 3)</td><td align="right">$897.00 USD</td></tr>
        <tr><td></td><td colspan="2" align="right">Total  $2,691.00 USD</td></tr></tbody></table>
        </td></tr><tr><td colspan="3"><i>*We calculate payments from the date of checkout.<i></i></i></td></tr>
        </tbody></table>
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIIQQYJKoZIhvcNAQcEoIIIMjCCCC4CAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQ=-----END PKCS7-----
">
    <table><tbody><tr><td align="center"><i>Sign up for</i></td></tr><tr><td><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_installment_plan_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" style="border: 0px;"></td></tr></tbody></table>
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Open in new window


I want to use PHP to extract the <input /> tag where name="encrypted". I think it's easier in jQuery but I'm trying to find out how to do this with PHP.

The other question I had to was how do I change the src="https://www.paypalobjects.com/en_US/i/btn/btn_installment_plan_LG.gif" to some other gif I have on my server?
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39829619
You might want to consider the logic flow here.  It looks like what you have there is an encrypted PayPal button, meant to be used "as is" in your web site.  I am not sure that changing it is a good idea.  But that aside, here is the code that will do those two things.
http://www.laprbass.com/RAY_temp_vkimura2007.php

<?php // RAY_temp_vkimura2007.php
error_reporting(E_ALL);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28354594.html#a39828759

$html = <<<EOD
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <table>
        <tbody><tr><td><input type="hidden" name="on0"></td></tr>
        <tr><td><input type="hidden" name="os0" value="option_0"></td>
        </tr><tr><td></td><td>Number of payments 3</td></tr>
        <tr><td></td><td>Start payments At Checkout</td></tr><tr><td></td><td><table><tbody><tr><th align="LEFT">Due*</th><th align="LEFT">Amount</th></tr>
        <tr><td>Every 1 Month (x 3)</td><td align="right">$897.00 USD</td></tr>
        <tr><td></td><td colspan="2" align="right">Total  $2,691.00 USD</td></tr></tbody></table>
        </td></tr><tr><td colspan="3"><i>*We calculate payments from the date of checkout.<i></i></i></td></tr>
        </tbody></table>
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIIQQYJKoZIhvcNAQcEoIIIMjCCCC4CAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQ=-----END PKCS7-----
">
    <table><tbody><tr><td align="center"><i>Sign up for</i></td></tr><tr><td><input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_installment_plan_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" style="border: 0px;"></td></tr></tbody></table>
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
EOD;

// GET THE INPUT TAG FOR name="encrypted"
$sig = 'name="encrypted"';
$arr = explode($sig, $html);
$arr = explode(PHP_EOL, $arr[1]);
$inp = '<input type="hidden" name="encrypted"' . $arr[0] . $arr[1];
echo htmlentities($inp);
echo PHP_EOL;

// REPLACE THE IMAGE TAG
$old = 'https://www.paypalobjects.com/en_US/i/btn/btn_installment_plan_LG.gif';
$new = 'path/to/your.gif';
$out = str_replace($old, $new, $html);
echo htmlentities($out);
echo PHP_EOL;

Open in new window

HTH, ~Ray
0
 

Author Closing Comment

by:Victor Kimura
ID: 39831202
@Ray, thanks! That works! =)
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39831244
Victor: Thanks for the points.  Hope you're having good luck with your project! ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Animated .jpg? 13 59
Store image url and display it for user profile 6 23
Form Processing in PHP 11 31
updating the date data 12 21
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now