ASP to PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jaydenw
Forum Newbie
Posts: 1
Joined: Thu Jul 14, 2011 11:12 pm

ASP to PHP

Post by Jaydenw »

Hi Guys,

I wonder if one of you gurus can help me.

I am trying to convert the following FORM processing code in to PHP:

<!-- Beginning of Google Tracking Script -->
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-########-#']);
_gaq.push(['_setDomainName', '.CustomerDomain.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'<% = Request.Form("orderID")%>', // order ID - required
'Your Company Name Here', // affiliation or store name
'<% = Request.Form("Total")%>', // total - required
'<% = Request.Form("tax")%>', // tax
'<% = Request.Form("shippingAmount")%>', // shipping
'<% = Request.Form("shipCity")%>', // city
'<% = Request.Form("shipState")%>', // state or province
'<% = Request.Form("shipCountry")%>' // country
]);
// add item might be called for every item in the shopping cart
// where your ecommerce engine loops through each item in the cart and
// prints out _addItem for each
_gaq.push(['_addItem',
'<% = Request.Form("orderID")%>', // order ID - required
'<% = Request.Form("sku1")%>', // SKU/code - required
'<% = Request.Form("product1")%>', // product name
'<% = Request.Form("option1")%>', // category or variation
'<% = Request.Form("price1")%>', // unit price - required
'<% = Request.Form("quantity1")%>' // quantity - required
]);
<% IF Len(Request.Form("product2")) > 0 THEN %>
_gaq.push(['_addItem',
'<% = Request.Form("orderID")%>', // order ID - required
'<% = Request.Form("sku2")%>', // SKU/code - required
'<% = Request.Form("product2")%>', // product name
'<% = Request.Form("option2")%>', // category or variation
'<% = Request.Form("price2")%>', // unit price - required
'<% = Request.Form("quantity2")%>' // quantity - required
]);
<% END IF
IF Len(Request.Form("product3")) > 0 THEN %>
_gaq.push(['_addItem',
'<% = Request.Form("orderID")%>', // order ID - required
'<% = Request.Form("sku3")%>', // SKU/code - required
'<% = Request.Form("product3")%>', // product name
'<% = Request.Form("option3")%>', // category or variation
'<% = Request.Form("price3")%>', // unit price - required
'<% = Request.Form("quantity3")%>' // quantity - required
]);
<% END IF
IF Len(Request.Form("product4")) > 0 THEN %>
_gaq.push(['_addItem',
'<% = Request.Form("orderID")%>', // order ID - required
'<% = Request.Form("sku4")%>', // SKU/code - required
'<% = Request.Form("product4")%>', // product name
'<% = Request.Form("option4")%>', // category or variation
'<% = Request.Form("price4")%>', // unit price - required
'<% = Request.Form("quantity4")%>' // quantity - required
]);
<% END IF
IF Len(Request.Form("product5")) > 0 THEN %>
_gaq.push(['_addItem',
'<% = Request.Form("orderID")%>', // order ID - required
'<% = Request.Form("sku5")%>', // SKU/code - required
'<% = Request.Form("product5")%>', // product name
'<% = Request.Form("option5")%>', // category or variation
'<% = Request.Form("price5")%>', // unit price - required
'<% = Request.Form("quantity5")%>' // quantity - required
]);
<% END IF
IF Len(Request.Form("product6")) > 0 THEN %>
_gaq.push(['_addItem',
'<% = Request.Form("orderID")%>', // order ID - required
'<% = Request.Form("sku6")%>', // SKU/code - required
'<% = Request.Form("product6")%>', // product name
'<% = Request.Form("option6")%>', // category or variation
'<% = Request.Form("price6")%>', // unit price - required
'<% = Request.Form("quantity6")%>' // quantity - required
]);
<% END IF %>

_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
<!-- End of Google Tracking Script -->

This script is basically for a thank you page for a 1 shopping cart product, I am trying to pull the transactional data from 1 Shopping Cart to Google analytics's to see revenue/transactional data.

This is the last response I got from the guy that wrote the script above-

The tracking code has ASP code to read the FORM posted transaction variables from 1SCart and place them in the applicable variables for Google.

I am not a .NET (aspx, I believe) programmer so you will either have to make the thank you page an ASP one or change the ASP code to match your programming language. Remember, because you need to process FORM posted variables, you will have to use a non-HTML language like ASP or PHP.

An example of the ASP code is:

'<% = Request.Form("orderID")%>', // order ID - required
'Company Name', // affiliation or store name
'<% = Request.Form("Total")%>', // total - required
'<% = Request.Form("tax")%>', // tax
'<% = Request.Form("shippingAmount")%>', // shipping
'<% = Request.Form("shipCity")%>', // city
'<% = Request.Form("shipState")%>', // state or province
'<% = Request.Form("shipCountry")%>' // country

You will need to take the ASP code between the two tick marks and replace it with applicable FORM processing code for ASPX or whatever language you are writing.

Note that if you have this code as a separate, included file that goes into a larger, ASPX file for example, an HTML extension is fine because whatever extension (e.g. ASPX) of the parent thank you file will cause the applicable code within the HTML file to be executed.

To test that my code works, if you can process ASP files, create a basic ThankYou.asp file with the tracking code right beneath the <head> tag. When 1SCart goes to this page, all of the proper variables will be processed and sent to Google. From there, you can convert it into ASPX.
-------------------------------------------
One of my friends suggested I come over to this forum and ask you guys because you are all super clever :)

Be great if you understand or could help me.

Thank you.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: ASP to PHP

Post by yacahuma »

what you are trying to do is very basic. You can find more details on any php tutorial. I never use asp but Request.Form("tax") in php will be $_POST['tax'] or $_GET['tax'] depending on of you use get or post in your form.
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: ASP to PHP

Post by Gopesh »

Hi,the same thing can be done in php.First of all u need a basic html form eg:

Code: Select all

<form action="destination.php" method="post>

Username:<input type="text" name="username">
<input type="submit" name="submit" value="Click">

</form>.

AS in ASP request.form can be here used by $_POST[] or $_GET[].

Code: Select all


<?php
 $username=$_post['username'];
echo $username;

?>

This is the basic form processing used in php.we can implement all the functions of asp.net ij php in a better easy way.Hope that it helps u...
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: ASP to PHP

Post by Jonah Bron »

@yacahuma is right, it's a pretty simple conversion. However, since you're outputting to Javascript, it's best to encode the string to JSON (with json_encode()) so that you know it's properly quoted, instead of having to worry about apostrophes in the output. Here's a small excerpt, and it's corresponding translation.

Code: Select all

<% IF Len(Request.Form("product2")) > 0 THEN %>
_gaq.push(['_addItem',
'<% = Request.Form("orderID")%>', // order ID - required
'<% = Request.Form("sku2")%>', // SKU/code - required
'<% = Request.Form("product2")%>', // product name
'<% = Request.Form("option2")%>', // category or variation
'<% = Request.Form("price2")%>', // unit price - required
'<% = Request.Form("quantity2")%>' // quantity - required
]);
<% END IF
IF Len(Request.Form("product3")) > 0 THEN %>
...equates to...

Code: Select all

<?php if (strlen($_POST['product2']) > 0): ?>
_gaq.push(['_addItem',
<?php echo json_encode($_POST['orderID']); ?>, // order ID - required
<?php echo json_encode($_POST['sku2']); ?>, // SKU/code - required
<?php echo json_encode($_POST['product2']); ?>, // product name
<?php echo json_encode($_POST['option2']); ?>, // category or variation
<?php echo json_encode($_POST['price2']); ?>, // unit price - required
<?php echo json_encode($_POST['quantity2']); ?> // quantity - required
]);
<?php endif;
if (strlen($_POST['product3']) > 0): ?>
You can see what I did at the different points and figure out how to translate the rest.
Last edited by Jonah Bron on Sun Aug 07, 2011 2:14 pm, edited 1 time in total.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: ASP to PHP

Post by twinedev »

Another good reference from going from one language to another (I use it when doing ASP work):

http://www.design215.com/toolbox/asp.php

Gives nice cross reference back and forth that if you do THIS in one language, you need to do THAT in the other.

-Greg
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: ASP to PHP

Post by genix2011 »

Hi,
<?php echo json_encode($_REQUEST['orderID']); ?>, // order ID - required
I wouldn't use $_REQUEST with forms, but instead $_POST, because $_REQUEST also contains the variables of $_COOKIE and $_GET.

Greets.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: ASP to PHP

Post by Jonah Bron »

@genix2011: good point, I googled it and .NET Request.Form is specifically POST data. Edited post to reflect that.
Post Reply