Jump to content
Larry Ullman's Book Forums

MikeMikeMike

Members
  • Content Count

    55
  • Joined

  • Last visited

Everything posted by MikeMikeMike

  1. Larry gives us the following code to write links for SSL access RewriteCond %{HTTPS} off RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L] the problem is that I'm on a shared server .This means that https://titanicraisins.com/checkout.php actually needs to be https://titanicraisins.c8.hostexcellence.com/checkout.php see live example here https://titanicraisins.c8.hostexcellence.com/checkout.php?session=72cac503b52a73308af0508fe462090a but I can't figure out how to change the htaccess file so that it does the rewrites For example, I tried both of the following, neither of which worked. RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://example.c8.hostexcellence.com/$1 [R=301,L] RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{example.c8.hostexcellence.com}/$1 [R=301,L] Any ideas? Also, I'm presuming that the htaccess file is the only place I would need to make the change, right? In other words, if a file in the application has the link www.titanicraisins.com/checkout.php then I don't have to change that link in the application because it gets rewritten in the htaccess file?
  2. On pag 178, Larry presents the code for the SSL rewrite. the rewritten destination is https://%{HTTP_HOST}/$1[R=301,L] What is the purpose of the % Because of the SSL situation on my shared server, I need to rewrite this a bit so I`m wondering about the purpose of the %. Thanks
  3. On page 169, it lists the SQL for the various tables. In the Carts table, for example, there is a primary key, but there is also a "Key" for product type and a "Key" for user id Some of the code looks like this PRIMARY KEY (`id`), KEY `product_type` (`product_type`, `product_id`), KEY `user_session_id`(`user_session_id`) Questions: 1) what is the purpose of the KEY? Please explain by comparing to PRIMARY KEY and also UNIQUE KEY, which is found in other tables. 2) Why is the input formatted that way for KEY. i.e. it has a name in quotes `product_type` and then it has more data after in parentheses?
  4. This is from page 258. I understand how ternary operators work usually, but I don't get the logic in the 4th line below and the explanation in the book wasn't sufficient for me. As far as I can read it, it says if "qty" is greater or equal than 0, use qty, otherwise use 1. but that doesn't make sense to me because then how does "1" ever get chosen? And where does the array come from in that line? And how do the filters work? Can someone write out the processing steps that take place in that line with the filters and the ternary operator. First, it does this... Then.... Then.... foreach ($_POST ['quantity'] as $sku => $qty) { list($sp_type, $pid) = parse_sku($sku); if (isset($sp_type, $pid)) { $qty = (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' ➥=>0)))?$qty:1; $r = mysqli_query($dbc, "CALL update_cart('$uid', '$sp_type', ➥$pid, $qty)");
  5. So you can designate the shortcut (in the third line) after it's already been used (in the first line)?
  6. Around page 197, Larry starts explaining some of the SQL statements that will be used in the stored procedures, but there's one thing I don't get. You see how he uses the short forms "gc" and "s" and "sc" throughout? SELECT gc.description, gc.image, CONCAT("C", sc.id) AS sku, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole, sc.price) AS name, sc.stock FROM specific_coffees AS sc INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id WHERE general_coffee_id=cat AND stock>0 I understand that "gc" refers to general coffees, but I don't understand how the database understands this query because when the tables were created, there were no short forms used. For example, the table for general coffees was created thus CREATE TABLE `general_coffees` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `category` varchar(40) NOT NULL, `description` tinytext, `image` varchar(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `type` (`category`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; so I would expect a query that uses "gc.description" to fail because how does it understand the "gc"? thanks if you can help.
  7. it's working now. Problem might have been that some invisible characters were included from a copy and paste. Not sure
  8. When I add the following code to my htaccess file according to the instructions starting at page 193, I'm getting a 500 error when I try to access my webpage. My web host hasn't been able to provide me with any answers. Any ideas? RewriteEngine on # For sales: RewriteRule ^shop/sales/?$ sales.php # For the primary categories: RewriteRule ^shop/([A-Za-z\ ] )/?$ shop.php?type=$1 # For specific products: RewriteRule ^browse/([A-Za-z\ \-] )/([A-Za-z\ \-] )/([0-9] )$ browse.php?type=$1&category=$2&id=$3 # For HTTPS pages: RewriteCond %{HTTPS} off RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
  9. sorry problem solved. i hadn't put the stored procedures into the database yet
  10. Hi, This question is about the 2nd ecommerce application (i.e. selling coffee). I loaded all the source code etc into a server to see what the site looks like before working through the chapters. (I also set up the databases and changed the htaccess file according to instructions). When I load the site, however, I am getting this error message about home.html. An error occurred in script '/blah/blah/views/home.html' on line 14: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given So this is a database query that has not succeeded, but I don't know what created it. I'm not sure if my database connection has failed, or if it's a path problem, or another reason. Any ideas... Looking at the source code, line 14 of home.html starts if (mysqli_num_rows($r) > 0) { echo '<dl class="special fright"> <dt><a href="/shop/sales/">Sale Items</a></dt>'; // Fetch each item: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<dd><a href="/shop/sales/#' . $row['sku'] . '" title="View This Product"><img alt="" src="/products/' . $row['image'] . '" /><span>' . $row['sale_price'] . '</span></a></dd>'; }
  11. I don't have the exact page handy, but when I was reading one of the earlier chapters in the book (I'm not at Chapter 7 yet) you said that all the SQL was available from the website, so I assumed that meant the SQL you were using in the chapter when you made that comment would also be on the website. If not, no problem. I just thought something might be missing, but I guess I misunderstood.
  12. The script downloads for this book only contain chapters 7,8,9 and 12. I think there's supposed to be more.
  13. problem solved. I had removed the "delimiter" (because I didn't see it in the code Larry posted).
  14. Hi Larry, I tried the code you gave me in your reply, but it didn't work. I wonder if I show you the steps I took through some screenshots if you can see what I'm doing wrong. This is the code I entered. As you can see, when I enter it, it gives me three different warnings (red Xs along the side). Did you get these warnings? After I click on "apply" for that code, it takes me to this pop up showing me the code that will apply to the database Then this is the error message I'm getting once I hit apply again Please let me know if you have any ideas about what I might be doing wrong. Thanks for your help. Cheers.
  15. There are several things about "Chapter 11 - Working With Command Line Arguments" (starting around page 449) that are not clear to me from the explanation in the book. I hope Larry can respond to them. I. Figure 11.21 shows the execution of the code on page 432. However, figure 11.21 makes reference to . /args.php but the code at the bottom of page 432 which created figure 11.21 doesn't make any reference to an args.php file. II. On page 453, as Larry is describing the steps to create number2.php , he provides the following code at step #2 If ($_SERVER['argc'] == 2) { and he says "Since the script will receive the script's name as its first argument, it would need to receive two arguments to be properly used." I don't understand this. Why does it need to receive two arguments to be properly used? What would the second argument be? III. On the same page, as Larry is describing step 3 in number2.php, he writes "First, the name of the file is identified as the second argument provided (the arguments list being an array, the indexiging begins at 0)" Here he says that the name of the file is identified as "the second argument." However, in my previous question (or step number 2 in the book), he says "Since the script will receive the script's name as its first argument." Is not the "name of the file" in step 3 the same as "the script's name" in step 2. If so, why does he say, in step 2, it will be "the first argument," but in step 3, he says it will be "the second argument" IV in figure 11.23, he runs an args.php script. Where do we get it? It wasn't in the files I downloaded? V On a mac, do I run it (once I located args.php) by doing php number2.php args.php and if so, what are the first and second arguments that he's talking about (which I mention in question 2 and 3 above). If I understand this code code]php number2.php args.php [/code] I only see one argument being passed, which is args.php Thank you for your help.
  16. Problem solved by entering this in the terminal pear install --force --alldeps Auth
  17. I got PEAR installed on my system. I'm working on Chapter 4, Authentication with Pear. Larry tells us to install Pear Auth package and also Pear DB. The Pear website says Pear DB is deprecated in favor of Pear MDB2, so I installed this latter package. However, when I ran login.php I got this warning Fatal error: Class 'DB' not found in /Users/michaelmitchell/pear/share/pear/Auth/Container/DB.php on line 150 Anyone have any idea what's going on here? This is the block of code referred to in the error message. The third line below starting if(!DB::.... is line 150 in the error message function _prepare() { if (!DB::isConnection($this->db)) { $res = $this->_connect($this->options['dsn']); if (DB::isError($res) || PEAR::isError($res)) { return $res; } } if ($this->options['auto_quote'] && $this->db->dsn['phptype'] != 'sqlite') { if (strpos('.', $this->options['table']) === false) { $this->options['final_table'] = $this->db->quoteIdentifier($this->options['table']); } else { $t = explode('.', $this->options['table']); for ($i = 0, $count = count($t); $i < $count; $i++) $t[$i] = $this->db->quoteIdentifier($t[$i]); $this->options['final_table'] = implode('.', $t); } $this->options['final_usernamecol'] = $this->db->quoteIdentifier($this->options['usernamecol']); $this->options['final_passwordcol'] = $this->db->quoteIdentifier($this->options['passwordcol']); } else { $this->options['final_table'] = $this->options['table']; $this->options['final_usernamecol'] = $this->options['usernamecol']; $this->options['final_passwordcol'] = $this->options['passwordcol']; } return true; }
  18. Problem solved. separate by colon include_path = ".:/Applications/MAMP/bin/php5.3/lib/php:/Users/michaelmitchell/pear/share/pear"
  19. Hi, I'm unsure of how to alter my php.ini file according to the instructions on the PEAR website It says "In every case, PEAR's php_dir should be in the include path. If not, add it in your system's php.ini." On my system(Mac 10.6.6), this is PEAR's php dir /Users/michaelmitchell/pear/share/pear On my system, this is the php.ini include path .:/Applications/MAMP/bin/php5.3/lib/php What should the resulting path look like in my php.ini? Do I delete the current path and replace it with PEAR's php dir path? or do I somehow integrate the two? Thanks for your help.
  20. Would Larry's Book Mac OS X Tiger Time Saving Techniques be useful for someone working with the latest Mac OS release (10.6.6.). Also, does it give instruction about how to use the Terminal?
  21. Taking a tip from the pear website, I created a test file to check the installation of Pear, and it worked. This was the code in the test file, which was in the same directory as login.php for Chapter 4 files. <?php require_once 'System.php'; var_dump(class_exists('System', false)); ?> However, when I try to run login.php, I'm getting the following error now (i.e. no longer a server error, rather seems more of a path error) Warning: require_once(Auth.php) [function.require-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/phpvqp2_scripts/Ch04/login.php on line 19 Fatal error: require_once() [function.require]: Failed opening required 'Auth.php' (include_path='.:/Applications/MAMP/bin/php5.3/lib/php') in /Applications/MAMP/htdocs/phpvqp2_scripts/Ch04/login.php on line 19 So that's that problem. I also note that because my username and password are both "root", I changed this line $options = array('dsn' => 'mysql://root:root@localhost/auth'); but I don't know if this could be the problem...
  22. Chapter 4 has an exercise with mcrypt but it doesn't explain how to install it or where to put it. I have no experience with installing anything from the command line (if that indeed is required), which is probably why I've also run into problems with Pear (see my other posts in this forum). Can anyone help out with this? I'm using a Mac 10.6.6. with libmycrypt 2.5.8.tar.gz file downloaded from mycrypt (i.e. my server only supports 2.5.8)
  23. Hi, Update: If you look at my first reply to this OP (which is the third post overall), it has the current status of the problem. Namely, I can get a test file to work (suggested by the Pear website) but not the login.php file from the Chapter 4 scripts. The details in this OP are probably not relevant anymore but I didn't want to erase them because I wasn't sure on forum rules. Nevertheless, please focus attention on the 3rd overall post if you can help. I'm not sure if the problem I'm having with Chapter 4 login.php is related to the unsolved problem I've had installing Pear (see my other question in this forum about installing pear on a Mac with MAMP). When I'm running login.php from chapter 4 I'm getting a server error. Besides the pear installation problem, here's what I did Since I was able to download the Pear files (at least some of them), I just plopped auth.php (which login.php requires) into the same directory as the scripts for chapter 4, like this Is that wrong? Moving on, Larry says that login.php I created the database and table etc. Larry says the database must be accessible to a MySQL user of "username@localhost" with a password of "password" so in the script he has this code $options = array('dsn' => 'mysql://username:password@localhost/auth'); But since my MySQL username is root and my password is root, I changed his code to $options = array('dsn' => 'mysql://root:root@localhost/auth'); but as mentioned I'm getting a server error. Anyone have any ideas? Is it because I'm not doing something right with Pear? or this code? I'm on a Mac 10.6.6. with MAMP installed. Actually, I just looked at Auth.php and saw that it requires other fils, and those files require other files, so I think this has to do with installing Pear properly so that the book files have access to the Pear files All of the pear files are burried in the bin folder (see below), while my files downloaded from Larry's book are in htdocs. What's the best way to set this up? Do I just copy the files into the same folder?
  24. Hi, UPDATE pear seems to be installed correctly (the test file recommended on pear website works in my installation) but when I try the login.php file from chapter 4 I am getting an error. There is details of that error in my first REPLY (i.e. not the OP) on this other thread My link I'm totally lost trying to install Pear on my Mac 10.6.6. (with MAMP installed ...PHP 5.3, MySQL 5.5.9). Note, I'm basically incompetent with command line so if you can help please explain as clearly as possible Someone at www.stackoverflow.com said I try curl pear.php.net/go-pear.phar > go-pear.phar This seemed to complete a download. After that I was told to sudo php go-pear.phar it asked for my password, which I entered, but then it just output ????Michael-Mitchells-MacBook-Pro:~ michaelmitchell$ Any ideas what I can do from here? Update, I found a recent blog post (linked below) that addresses this ????? issue when working with Phar files in OS. It tells me to set my ini directive detect_unicode = Off but I'm not 100% sure how to do this, and then once it's done, how to continue http://technosophos.com/content/php-phar-command-line-errors-os-x-running-php-somephar-generates Update I typed detect_unicode = Off in my php.ini file but still had the same ?????? output. I'm not sure if I put detect_unicode = Off correctly in the file. I just opened it up and typed it in. Any ideas anyone? As you can see from the image below, the pear files are in my directory but because I couldn't do sudo php go-pear.phar I don't think it's function. Even though there are some Pear files, they are all in the bin folder and Larry's scripts are in htdocs. Is this how they're supposed to be set up?
×
×
  • Create New...