Hello.
I've been viewing this site for a long time, but finally decided to join and ask for help. I'm using citrusDB and a sample code from authorize.net and I want to pass off some information from the citrus DB to the authorize.net code. I've been trying to do this with sessions all night and can't seem to get it. If it means anything, I set up two PHP files one that sets a session variable, and the second that displays it, and that is working fine so I'm not convinced it's a configuration issue.

Here's the code on the citrus file:

        echo '</table>';
        echo "<p><a href=\"$payment_url\">$l_paybillonline</a>";
$ccproc = $total_due;
echo $ccproc;
$_SESSION['ccproc'] = $ccproc;
echo $_SESSION['ccproc'];

                break;

What i tried to do here was set the session variable "ccproc" then display t, and it DOES dislay properly.

Then on the second page:

echo $_SESSION['ccproc'];

and it does not display the same number. As a test, I am using "100.00", so for the first one, it displays "100.00" where I echo both $ccproc, and the session variable.

My error log is saying undefined index on the second page, but when I did this in a test environment with just a simple variable, it was coded exactly the same way, but it worked fine. Any thoughts?

-Austin

Do you have session_start(); at the beginning of your script on every page the session data is needed?

Going to need more code to understand what you are doing. Can you post it?

This is the code from the file that displays the information. It's basically giving me a total dollar amount that the customer owes, and when they click the pay bill online link, I want it to pull the amount owed and send it to the next php document which processes the credit card. Almost all the way at the bottom is where my variables are struggling. I set ccproc to the same amount that total_due was, and then echo'd it to verify that it took, which it does.

    /*--------------------------------------------------------------------*/
    // Billing
    /*--------------------------------------------------------------------*/
    case 'view_bill':
            // view their invoices (much like the invoice maintenance tool)
        echo "<h3>$l_recentpayments</h3>";
        echo "<table cellspacing=2 cellpadding=2 border=0>
        <td bgcolor=\"#ddcccc\" width=100><b>$l_id</b></td>
        <td bgcolor=\"#ddcccc\" width=130><b>$l_date</b></td>
        <td bgcolor=\"#ddcccc\" width=200><b>$l_type</b></td>
        <td bgcolor=\"#ddcccc\" width=100><b>$l_status</b></td>
        <td bgcolor=\"#ddcccc\" width=100><b>$l_response</b></td>
        <td bgcolor=\"#ddcccc\" width=150><b>$l_amount</b></td>";

        // get the billing_history for this account, the account number 
        // is stored in the corresponding billing record

        $query = "SELECT p.id p_id, p.creation_date p_cdate, p.payment_type 
        p_payment_type, p.status p_status, p.billing_amount p_billing_amount, 
        p.response_code p_response_code, c.account_number c_acctnum,
        b.account_number b_acctnum, b.id b_id
        FROM payment_history p 
        LEFT JOIN billing b ON p.billing_id = b.id
        LEFT JOIN customer c ON b.account_number = c.account_number
        WHERE b.account_number = '$user' ORDER BY p.id DESC LIMIT 3";

        $DB->SetFetchMode(ADODB_FETCH_ASSOC);
        $result = $DB->Execute($query) or die ("$l_queryfailed");


        while ($myresult = $result->FetchRow())
        {
            $id = $myresult['p_id'];
            $date = $myresult['p_cdate'];
            $type = $myresult['p_payment_type'];
            $status = $myresult['p_status'];
            $response = $myresult['p_response_code'];
            $amount = $myresult['p_billing_amount'];

            print "<tr bgcolor=\"#ffeeee\">";
            print "<td>$id</td>";
            print "<td>$date</td>";
            print "<td>$type</td>";
            print "<td>$status</td>";
            print "<td>$response</td>";
                    print "<td>$amount</td>";
        }

        echo '</table>';

        echo "<h3>$l_recentbilling</h3>";
        echo "<table cellspacing=2 cellpadding=2 border=0>
        <td bgcolor=\"#ccdddd\" width=100><b>$l_invoicenum</b></td>
        <td bgcolor=\"#ccdddd\" width=130><b>$l_date</b></td>
        <td bgcolor=\"#ccdddd\" width=200><b>$l_type</b></td>
        <td bgcolor=\"#ccdddd\" width=100><b>$l_from</b></td>
        <td bgcolor=\"#ccdddd\" width=100><b>$l_to</b></td>
        <td bgcolor=\"#ccdddd\" width=100><b>$l_newcharges</b></td>
        <td bgcolor=\"#ccdddd\" width=150><b>$l_total</b></td>";

        // get the billing_history for this account, the account number is 
        // stored in the corresponding billing record

        $query = "SELECT h.id h_id, h.billing_id h_bid, h.billing_date h_bdate, 
        h.billing_type h_btype, h.from_date h_from, h.to_date h_to, h.total_due 
        h_total, h.new_charges h_new_charges, c.account_number c_acctnum, 
        b.account_number b_acctnum, b.id b_id 
        FROM billing_history h 
        LEFT JOIN billing b ON h.billing_id = b.id  
        LEFT JOIN customer c ON b.account_number = c.account_number
        WHERE b.account_number = '$user' ORDER BY h.id DESC LIMIT 3";

        $DB->SetFetchMode(ADODB_FETCH_ASSOC);
        $result = $DB->Execute($query) or die ("$l_queryfailed");

        while ($myresult = $result->FetchRow())
        {
            $id = $myresult['h_id'];
            $billing_date = $myresult['h_bdate'];
            $billing_type = $myresult['h_btype'];
            $from_date = $myresult['h_from'];
            $to_date = $myresult['h_to'];
            $new_charges = $myresult['h_new_charges'];
            $total_due = $myresult['h_total'];

            print "<tr bgcolor=\"#eeffff\">";
            print "<td>$id</td>";
            print "<td>$billing_date</td>";
            print "<td>$billing_type</td>";
            print "<td>$from_date</td>";
            print "<td>$to_date</td>";
            print "<td>$new_charges</td>";
            print "<td>$total_due</td>";
        }

        echo '</table>';
        echo "<p><a href=\"$payment_url\">$l_paybillonline</a>";
$ccproc = $total_due;
echo $ccproc;
$_SESSION['ccproc'] = $ccproc;
echo $_SESSION['ccproc'];

                break;

    case 'pay_bill':
            // link to external online payment form?
                break;

The second page that sends this information to my processor is coded below.

<!--
This sample code is designed to connect to Authorize.net using the AIM method.
For API documentation or additional sample code, please visit:
http://developer.authorize.net
-->
<?PHP
session_start();
$ccproc="";

$post_url = "https://secure.authorize.net/gateway/transact.dll";

echo "<b>TEST</b>";
echo $_SESSION['ccproc'];



$post_values = array(

    // the API Login ID and Transaction Key must be replaced with valid values
    "x_login"           => "73sG4Yj2P",
    "x_tran_key"        => "6a99w73c4XJK5Ata",

    "x_version"         => "3.1",
    "x_delim_data"      => "TRUE",
    "x_delim_char"      => "|",
    "x_relay_response"  => "FALSE",

    "x_type"            => "AUTH_CAPTURE",
    "x_method"          => "CC",
    "x_card_num"        => "4111111111111111",
    "x_exp_date"        => "0115",

    "x_amount"          => $_SESSION['ccproc'],
    "x_description"     => "Sample Transaction",

    "x_first_name"      => "John",
    "x_last_name"       => "Doe",
    "x_address"         => "1234 Street",
    "x_state"           => "WA",
    "x_zip"             => "98004"
    // Additional fields can be added here as outlined in the AIM integration
    // guide at: http://developer.authorize.net
);


// This section takes the input fields and converts them to the proper format
// for an http post.  For example: "x_login=username&x_tran_key=a1B2c3D4"
$post_string = "";
foreach( $post_values as $key => $value )
    { $post_string .= "$key=" . urlencode( $value ) . "&"; }
$post_string = rtrim( $post_string, "& " );

// The following section provides an example of how to add line item details to
// the post string.  Because line items may consist of multiple values with the
// same key/name, they cannot be simply added into the above array.
//
// This section is commented out by default.
/*
$line_items = array(
    "item1<|>golf balls<|><|>2<|>18.95<|>Y",
    "item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y",
    "item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y");

foreach( $line_items as $value )
    { $post_string .= "&x_line_item=" . urlencode( $value ); }
*/

// This sample code uses the CURL library for php to establish a connection,
// submit the post, and record the response.
// If you receive an error, you may want to ensure that you have the curl
// library enabled in your php configuration
$request = curl_init($post_url); // initiate curl object
    curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
    curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
    curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
    curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
    $post_response = curl_exec($request); // execute curl post and store results in $post_response
    // additional options may be required depending upon your server configuration
    // you can find documentation on curl options at http://www.php.net/curl_setopt
curl_close ($request); // close curl object

// This line takes the response and breaks it into an array using the specified delimiting character
$response_array = explode($post_values["x_delim_char"],$post_response);

// The results are output to the screen in the form of an html numbered list.
echo "<OL>\n";
foreach ($response_array as $value)
{
    echo "<LI>" . $value . "&nbsp;</LI>\n";
}
echo "</OL>\n";
// individual elements of the array could be accessed to read certain response
// fields.  For example, response_array[0] would return the Response Code,
// response_array[2] would return the Response Reason Code.
// for a list of response fields, please review the AIM Implementation Guide
?>
</BODY>
</HTML>

My thoughts were if I can at least get the session variable to display on this page, I can use the information to process the card. WHen I call it, it just appears blank, and when I look at the error log on the server, it shows undefined index on the second page of code.

Try adding ob_start() before headers and ob_end_flush() to end. Do this for both pages. ob = output buffer.

Use session_start on top of page.
There should be no other HTML codes, html comments or any white space.

I tried the ob code and still no dice. I can provide a link to the test server I'm using if anyone would like to see the code for the rest of the design. Would there be a setting elsewhere in the php file disabling session variables?

what php editor you are using?Is it has error highlighting on? If so check if you have any errors in your pages after that you can start your session in the connection file and use require once or closures in all your code with the connection file and use session_start(); in al you pages like this

<?php 
require_once('conection.php');
session_start();


?>

I'm usng Notepad++. We decided to go a different route to process the payment and it seems to be working. Thanks for all of the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.