Jump to content
Larry Ullman's Book Forums

dmx1

Members
  • Posts

    70
  • Joined

  • Last visited

Everything posted by dmx1

  1. Hi Larry, Hope you are well. If I am on the 'checkout.php' page, and then I go directly to the 'login.inc.php' page from the 'checkout.php' page, after I successfully log in, I want to go straight back to the 'checkout.php' page. I want to go directly back to the checkout.php from the 'login.inc.php' page, only after initially coming from the 'checkout.php page', and not from any other page. So whatever page I am on, and I go directly to the 'login.inc.php' from that page, I want to be redirected straight back to the previous page. I have tried to implement this, but I am not having much luck. PS: I am trying to include the login feature from exercise 1. Thank you. regards
  2. Hi Larry, I copied your code line to line, and the only reference is in the billing.js file on line 16 var cc_number = $('#cc_number').val(), Also, it's in the billing_stripe.html form <div class="field"><label for="cc_number"><strong>Card Number</strong></label><br /><input type="text" id="cc_number" autocomplete="off" /></div> Other than that, I can't see it defined anywhere else. QU: Do I need to define the variable 'cc_number' again somewhere else, because I literally copied your entire code and assumed everything is fine, so I am reluctant to change anything. I have run out of ideas regards
  3. Hi Larry, I am having a few problems regarding the 'billing_stripe.php' file. I wrote the code below that's in my 'billing_stripe.php' file. When I get to the line: $cc_last_four = substr($cc_number, -4); An error is thrown up and it says: 'Undefined variable: cc_number'. I have tried everything but I can't seem to find out why it's saying that the cc_number variable is undefined. Qu 1: Do you have any suggestions as to what might be the problem? Qu 2: Is the code in the billing_stripe.php file below correct, or do I need to take out some sections? Code for 'billing_stripe.php' file <?php // This file is the second step in the checkout process. // It takes and validates the billing information. // This updated versions uses Stripe. // This script is created in Chapter 15. // Require the configuration before any PHP code: require('./includes/config.inc.php'); // Start the session: session_start(); // The session ID is the user's cart ID: $uid = session_id(); // Check that this is valid: if (!isset($_SESSION['customer_id'])) { // Redirect the user. $location = 'https://' . BASE_URL . 'checkout.php'; header("Location: $location"); exit(); } // Require the database connection: require(MYSQL); // Validate the billing form... // For storing errors: $billing_errors = array(); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] === 'POST') { //if (get_magic_quotes_gpc()) { $_POST['cc_first_name'] = stripslashes($_POST['cc_first_name']); // Repeat for other variables that could be affected. // } // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $_POST['cc_first_name'])) { $cc_first_name = $_POST['cc_first_name']; } else { $billing_errors['cc_first_name'] = 'Please enter your first name!'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $_POST['cc_last_name'])) { $cc_last_name = $_POST['cc_last_name']; } else { $billing_errors['cc_last_name'] = 'Please enter your last name!'; } // Check for a Stripe token: if (isset($_POST['token'])) { $token = $_POST['token']; } else { $message = 'The order cannot be processed. Please make sure you have JavaScript enabled and try again.'; $billing_errors['token'] = true; } // Check for a street address: if (preg_match ('/^[A-Z0-9 \',.#-]{2,160}$/i', $_POST['cc_address'])) { $cc_address = $_POST['cc_address']; } else { $billing_errors['cc_address'] = 'Please enter your street address!'; } // Check for a city: if (preg_match ('/^[A-Z \'.-]{2,60}$/i', $_POST['cc_city'])) { $cc_city = $_POST['cc_city']; } else { $billing_errors['cc_city'] = 'Please enter your city!'; } // Check for a state: /*if (preg_match ('/^[A-Z]{2}$/', $_POST['cc_state'])) { $cc_state = $_POST['cc_state']; } else { $billing_errors['cc_state'] = 'Please enter your state!'; } */ // Check for a zip code: if (preg_match ('/^[a-z]{1,2}\d[a-z\d]?\s*\d[a-z]{2}$/i', $_POST['cc_zip'])) { $cc_zip = $_POST['cc_zip']; } else { $billing_errors['cc_zip'] = 'Please enter your zip code!'; } if (empty($billing_errors)) { // If everything's OK... // Check for an existing order ID: if (isset($_SESSION['order_id'])) { // Use existing order info: $order_id = $_SESSION['order_id']; $order_total = $_SESSION['order_total']; } else { // Create a new order record: // Get the last four digits of the credit card number: // Temporary solution for Stripe: // $cc_last_four = 1234; $cc_last_four = substr($cc_number, -4); // PROBLEM-----------------------PROBLEM LINE---------------------------PROBLEM LINE // Call the stored procedure: $shipping = $_SESSION['shipping'] * 100; $r = mysqli_query($dbc, "CALL add_order({$_SESSION['customer_id']}, '$uid', $shipping, $cc_last_four, @total, @oid)"); // Confirm that it worked: if ($r) { // Retrieve the order ID and total: $r = mysqli_query($dbc, 'SELECT @total, @oid'); if (mysqli_num_rows($r) == 1) { list($order_total, $order_id) = mysqli_fetch_array($r); // Store the information in the session: $_SESSION['order_total'] = $order_total; $_SESSION['order_id'] = $order_id; } else { // Could not retrieve the order ID and total. unset($cc_number, $cc_cvv, $_POST['cc_number'], $_POST['cc_cvv']); trigger_error('Your order could not be processed due to a system error. We apologize for the inconvenience.'); } } else { // The add_order() procedure failed. trigger_error('Your order could not be processed due to a system error. We apologize for the inconvenience.'); } } // End of isset($_SESSION['order_id']) IF-ELSE. // ------------------------ // Process the payment! if (isset($order_id, $order_total)) { try { // Include the Stripe library: require_once('includes/stripe-php-master.php'); // set your secret key: remember to change this to your live secret key in production // see your keys here https://manage.stripe.com/account Stripe::setApiKey('sk_test_5671Ho5BXJqZPKqEIbC9WJInaYpkgFz0TKM00yZFexsOh'); // Charge the order: $charge = Stripe_Charge::create(array( 'amount' => $order_total, 'currency' => 'GBP', 'card' => $token, 'description' => $_SESSION['email'], 'capture' => false ) ); // echo '<pre>' . print_r($charge, 1) . '</pre>';exit; // Did it work? if ($charge->paid == 1) { // Add slashes to two text values: $full_response = addslashes(serialize($charge)); // Record the transaction: $r = mysqli_query($dbc, "CALL add_charge('{$charge->id}', $order_id, 'auth_only', $order_total, '$full_response')"); // Add the transaction info to the session: $_SESSION['response_code'] = $charge->paid; // Redirect to the next page: $location = 'https://' . BASE_URL . 'final.php'; header("Location: $location"); exit(); } else { // Charge was not paid! $message = $charge->response_reason_text; } } catch (Stripe_CardError $e) { // Stripe declined the charge. $e_json = $e->getJsonBody(); $err = $e_json['error']; $message = $err['message']; } catch (Exception $e) { // Try block failed somewhere else. trigger_error(print_r($e, 1)); } } // End of isset($order_id, $order_total) IF. // Above code added as part of payment processing. // ------------------------ } // Errors occurred IF } // End of REQUEST_METHOD IF. // Include the header file: $page_title = 'EFYHAH - Checkout - Your Billing Information'; include('./includes/checkout_header.html'); // Get the cart contents: $r = mysqli_query($dbc, "CALL get_shopping_cart_contents('$uid')"); if (mysqli_num_rows($r) > 0) { // Products to show! if (isset($_SESSION['shipping_for_billing']) && ($_SERVER['REQUEST_METHOD'] !== 'POST')) { $values = 'SESSION'; } else { $values = 'POST'; } include('./views/billing_stripe.html'); } else { // Empty cart! include('./views/emptycart.html'); } // Finish the page: include('./includes/footer.html'); ?>
  4. Hi Larry, I sorted the problem. Please ignore the previous posts. Thank you!
  5. Note: For some reason, the lines are getting spaced out Hi Larry, I made a slight adjustment in the checkout.php file. I simply moved the session_id($uid) and session_start() lines to the top of the page, and it works. I can now go straight to the checkout.php page without it giving me the error 'session_id(): Cannot change session id when headers already sent' For example on the checkout.php page I commented out the session_id($uid) and session_start() lines, and just put them right at the start of the checkout.php page on page 297 as follows: <?php session_id($uid); session_start(); require('./includes/config.inc.php'); // Check for the user's session ID, to retrieve the cart contents: if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (isset($_COOKIE['SESSION']) && (strlen($_COOKIE['SESSION']) === 32)) { $uid = $_COOKIE['SESSION']; // Use the existing user ID: //session_id($uid); // Start the session: //session_start(); } else { // Redirect the user. $location = 'http://' . BASE_URL . 'cart.php'; header("Location: $location"); exit(); } } else { // POST request. session_start(); $uid = session_id(); } Qu 1: Can I leave it like this, or won't this work? Qu 2: Based on what I just did, what do you think could be the problem? It seems the problem starts after the require('./includes/config.inc.php') line. If I could just simply put the code at the top of the page, this would solve the problem, but I don't know if this is allowed. Also, I would like to find out why the original code in the checkout.php page stops working and throws out the error message: session_id(): Cannot change session id when headers already sent' regards
  6. I will try out your suggestions and let you know how far I have got to. Appreciate that Larry! Thank you!
  7. Hi Larry, I put the website online on a hosting server with a few html design alterations. It works fine up until when I try and get onto the checkout.php page. It gives me the following error: 'checkout.php' on line 10: session_id(): Cannot change session id when headers already sent' I removed all the ?> tags from the all .php files. I have spent two whole days trying to find out what the problem is, but nothing. The problem occurs when I get to the line session_id($uid); on the 'checkout.php' page on page 297. If I remove the lines: session_id($uid); session_start(); in the checkout.php on page 297, I then get access to the 'checkout.php' page. For some reason, the session_id($uid); and session_start() lines are the problematic lines. Can you suggest what it could be, and what I could do to fix the problem. Thank you regards
  8. Hi Larry, Hope you are well. Qu 1: wanted to know, how would I change the price of a product based on the different sizes? So if a customer goes to the product details page for a product, it would have all the different size options. The product would have a default option with a default size. If the customer clicked on the small size the price would change according to that size. Similarly a price change for sizes medium and large. I could then add that size and price to the shopping cart. Qu 2: And lastly how would I allow the user to select different colors for the product, and be able to add that color product to the database? I could then add that color for that product to the shopping cart Thanks in advance
  9. Qu 1: What I mean, is zend mail secure and efficient enough to be used as a professional email sender in a fully functional ecommerce website? Qu 2: if zend mail is not meant for a professional environment or not secure enough, what professional email sender would you recommend? regards
  10. Ok, that's fine. So would I be able to use the zend mail in a production environment? Meaning, if I upload the whole application to my hosting provider, will i be able to use their smtp/email settings along with the zend mail code you wrote, to implement sending emails using zend mail?
  11. Hi Larry, Happy New Year! I'm having problems sending and receiving emails via the zend-mail procedure. The code on page 434 runs fine without any errors, but I am just not receiving any emails. I used the exact code on page 434, but that wasn't working, so I tried to configure smtp settings, thinking that may be the missing solution, which is: // Create a new mail: use Zend\Mail; use Zend\Mime\Message as MimeMessage; use Zend\Mime\Part as MimePart; use Zend\Mail\Transport\Smtp as SmtpTransport; use Zend\Mail\Transport\SmtpOptions; // Create the parts: $html = new MimePart($body_html); $html->type = "text/html"; $plain = new MimePart($body_plain); $plain->type = "text/plain"; // Create the message: $body = new MimeMessage(); $body->setParts(array($plain, $html)); // Establish the email parameters: $mail = new Mail\Message(); $mail->setFrom('myemaill@aol.com', 'Dmx'); $mail->addTo($_SESSION['email'], 'Tom'); $mail->setSubject("Order #{$_SESSION['order_id']} at the Coffee Site"); $mail->setEncoding("UTF-8"); $mail->setBody($body); $mail->getHeaders()->get('content-type')->setType('multipart/alternative'); // Setup SMTP transport using LOGIN authentication $transport = new SmtpTransport(); $options = new SmtpOptions(array( 'name' => 'localhost', 'host' => 'localhost', 'connection_class' => 'login', 'connection_config' => array( 'username' => 'myusername', 'password' => 'mypassword', ), )); $transport->setOptions($options); $transport->send($mail); The above code then gave me the following error: 'An error occurred in script '/Applications/MAMP/htdocs/vendor/zendframework/zend-mail/src/Protocol/AbstractProtocol.php' on line 223: stream_socket_client(): unable to connect to tcp://localhost:25 (Connection refused)' So I'm at a loss as to what to do now. I know the zend-mail code has changed a lot since you wrote the book, but I just can't seem to find any success in finding the correct code needed to send and receive emails. Qu: Please could you help, by giving me the correct code needed to send emails using zend-email. I'm using a mac and mamp. Thank you regards
  12. Hi Larry, On page 344, in the 'tip' section, you wrote that in the forum there is a way on how to add general coffee and goodie types. I searched the forum, but cannot find the solution. Qu 1: Could you possibly send me the scripts for both solutions or direct me exactly to where I can the solution please. Thank you. regards
  13. Hi Larry, Seasons greetings to you. Hope you had a good one. Problem 1 Regarding the site administration section with the following url: localhost/admin/ When I click on the 'customers' link on the horizontal menu in the admin section, the 'customers.php' page doesn't exist. It just goes to the following url: localhost/admin/# I have looked and I can't find the 'customers.php' page. Qu 1: Can you let me know where I can find the 'customers.php' and script, in order to make the above link work and produce the correct results. Problem 2 When I click on the 'orders' link in the horizontal menu, in the admin section, in order to view the orders, and then click on the 'customer name' link to view the customer who made the order, I am sent to the following link, and then presented with the following error message: localhost/admin/view_customer.php?cid=58 'Not found. The requested URL was not found on this server.' Again, there is no 'view_customer.php' in any of the folders. Qu 2: Can you let me know where I can find the 'views_customers.php' in order to make the above link work, and produce the correct results. Thank you. regards
  14. Looking at it again, I think it's the same version that you are using, but just a different link. It's version 1.1.8
  15. Hi Larry, I am using the following version which can be found at: https://github.com/objco/anet_php_sdk It's called anet_php_sdk-master The reason I am using this version is because the link developer.authorize.net/downloads where you said we could download the version you are using on page 325, is obsolete, so I had no choice but to find another link where there was another version. I believe I am using a slightly different version from the one you are using. regards
  16. Upon further research, the problem happens in the billing.php page, specifically at the line: $response = $aim->authorizeOnly(); All my entered values are entered correctly, but when the following class is called in the 'anet_php_sdk' folder: class AuthorizeNetAIM extends AuthorizeNetRequest() and then the following method inside the class is called: public function authorizeOnly($amount = false, $card_num = false, $exp_date = false) { ($amount ? $this->amount = $amount : null); ($card_num ? $this->card_num = $card_num : null); ($exp_date ? $this->exp_date = $exp_date : null); $this->type = "AUTH_ONLY"; return $this->_sendRequest(); } The following variable parameters: '$amount', '$card_num', and '$exp_date' all return null values Up until then, all the variables '$amount', '$card_num', and '$exp_date' all have valid values, but for some reason, they are not being passed into the parameters inside the above 'authorizeOnly($amount = false, $card_num = false, $exp_date = false)' function So the values that have been entered for the credit card details, are never passed into the above method because the boolean 'false' is assigned to these values. I tried to take away all the 'false' values in the parameter in the 'authorizeOnly()' function, but all I got back was a blank 'billing.php' page. So because all 'null' values are returned in the above 'authorizeOnly()' method, the following method in the 'billing.php' page, returns false, and the payment is never processed. if ($response->approved) {) Can you help me solve this problem please. Thank you. regards
  17. Hi Larry, Hope you are well. I have hit a brick wall on page 336 on Effortless Ecommerce 2nd edition. I have written all the code up to this point. The only modification I have made is changing the urls beginning with 'https' to 'http' in the billing.php page eg: $location = 'https://' . BASE_URL . 'checkout.php'; to $location = 'http://' . BASE_URL . 'checkout.php'; and $location = 'http://' . BASE_URL . 'final.php'; to $location = '/final.php'; These are temporary adjustments because I don't have a ssl certificate installed yet. When I get to the billing.php page and fill out all the form details which are all correct. I then click the 'place order' button to process the payment, and absolutely nothing happens. My 'API_LOGIN_ID' id and 'TRANSACTION_KEY' are both correct. The billing.php page just refreshes with the same values in the fields, and not going to the 'final.php' page. I debugged the program and when I got to the billing.php page, when I got to the 'Process payment section' // Process the payment! if (isset($order_id, $order_total)) { I encountered an error at the following line: '$response = $aim->authorizeOnly();' all the values contained in the '$response' variable came back as null, ie: _response_array = null approved = (bool) false declined = null error = (bool)true response_code = null transaction_id = null invoice_number = null description = null customer_id = null first_name = null last_name = null etc so the following line: $r = mysqli_query($dbc, "CALL add_transaction($order_id, '{$response->transaction_type}', $order_total, {$response->response_code}, '$reason', {$response->transaction_id}, '$full_response')"); came back as false so if ($response->approved) returned false I don't understand what happened because all the entered fields in the 'billing.php' page were correct, but for some reason, when passed to Authorize.net, the values are failing and returning null values. I have tried for 3 full days to work this out but no luck. Can you please help Thank you regards
  18. Hi Larry, Hope you are well. I am having serious problems trying to implement a ssl certificate in order to test the https://localhost/checkout.php page in chapter 10. I am using a macbook pro, and using mamp. I tried created all the necessary files needed to to generate the certificate, but my problem starts when i try and edit the httpd.conf and http-ssl.conf files. In the httpd.conf file i have the following settings: Listen 8888 ServerName localhost:8888 Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf In my httpd-ssl.conf file I have: Listen 443 <VirtualHost *:443> ServerName localhost:8888 SSLCertificateFile "/mypath/server.crt" SSLCertificateKeyFile "/mypath/server.key" I then try and restart the apache server, but it states that apache cannot be started with those settings. I then changed the port to 80, and apache started, but i encountered other problems when trying to load the ecommerce site from localhost. Can you tell me a way I can run ssl on localhost so i can navigate to the https://localhost/checkout.php page and thus throughout the site please. Thank you. regards
  19. Hi Larry, I am trying to check, and upgrade mysql databases. I have tried everything, but no luck. When i try and upgrade the databases by clicking the upgrade option, I get the error message: 'mysql_upgrade: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) while connecting to the MySQL server Upgrade process encountered error and will not continue' Qu: I changed the password in the config.inc.php file, but it still won't work. Can you give me a solution to fix the problem, so I can upgrade the mysql databases. Thanks regards
  20. Ok. Thank you Jay. I will try and implement your instructions. Really appreciate you taking time out to reply. regards
×
×
  • Create New...