Jump to content
Larry Ullman's Book Forums

Terry

Members
  • Posts

    87
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Terry

  1. Oh. I did not know that and have never used it before. Instead what I do is something like: include('/subfolder1/subfolder2/'); This goes down two folders by name from the current file that is being called from. I didn't know I should add a period there at the beginning because it works, I maybe doing it wrong and never knew it.
  2. quit(); I think what happened is you intended to type exit(); instead of quit(); There a few places I found this "typo" but one is: Chapter 4 page 80. At the end of redirect line just in case the redirect doesn't work php won't keep on processing the file and display content on the page that shouldn't be shown. I do this too. You use exit() a lot in the book, I looked it up at php.net and it says this is used to display a message before stopping process of the file. Though in most the cases I see you using this there is no message so in these cases wouldn't it be better to use quit; ? Besides the message thing, what benefits are there to using exit() vs quit or is it just personal preference? I also found a typo on page 87 in section 9 you have create_password_hash($p) where it should be get_password_hash($p).
  3. I learn by context. I took the code provided in the book and derived that BASE_URI is the file path to the web root based on the example code and the description provided when referencing that bit of code in the book. If you notice BASE_URI is a definition, defined by larry. You could rename that to WEB_ROOT to make it more descriptive so at a glance you know what it is. Wikipedia defines URI as: http://en.wikipedia.org/wiki/Uniform_Resource_Identifier In context of PHP code I have ever seen, URI is file path location to the file or folder while URL is the website address to the same, the www.somesite.com address OR ip address to the site. Though you can use the www.somesite.com as the URI it does make it confusing and isn't really good to interchangeably use URI as URL as you will get confused to what each is. I say URI is universal resource indicator, wikipedia and others say it is uniform resource identifier... whatever, as long as I know what it does. So basically URI is the file path, the operating systems way of knowing where things are whether it is unix/linux or windows. URL is the internet address to the same location. They both work differently but point to the same places. Now, in my mind there has to be a distinction because there are certain situations where URL can't be used like when you are accessing resources, files or folders outside of the web accessible folders. URL will NEVER get to those resources and you have to be able to get there so a different method needs to be used, in those cases URI is vital and why in my mind the distinction between URI and URL. Though in your code you may want to change define names to WEB_ROOT vs BASE_URI, but the reason you should know what they are is so when you communicate with someone else there is a common reference, even if the other person doesn't know what URI is, if you know what it is and can explain what you are talking about then you both can use the term URI to reference, instead of saying web root, or file path because URI by itself isn't really web root it is file path, base uri is web root though I have NEVER used that term. I dunno, I just learn by context and use of code, it can be confusing when you see multiple examples and different people use this in different ways but now that you understand the purpose behind URI and URL you will use them correctly. Anyway that is my thoughts on that, right or wrong, it works for me.
  4. EDIT--- I meant to ask about difference between exit() and exit in this thread. I got mixed up with "quit" due to lack of sleep and confusing two different languages php and autoIT3.... Answer: there are three versions of the exit function... exit, exit() and exit('some message') all three do samething but the last example allows you to send a message. More info available about this at php.net. for some reason exit() doesn't work for me that well at least not on php 5.2 but exit; does so if you have issues with the exit command as written in the book try WITH OUT the () and just put exit; it does the samething. ---- Hi, I noticed in your book that you use quit(); to exit the program. This NEVER works for me, I get errors actually in php when I use that, but quit; works fine. Also when you move up a folder you use a single ./ instead of ../ why is this? I am just curious, because for me those two things as written in the book don't work for me at all, I have to alter using quit; AND ../ Maybe it is just my host but your versions don't work for me and was curious why you use those and what host you use that those work for you? Thanks.
  5. This particular book is not meant for beginners, this is more of an intermediate book that assumes you have basic knowledge of PHP before coming to it. You may find one of Larry's other books most helpful in learning more of the basics, some have turned to the new PHP 6 and MySQL 5 book to help them learn what they haven't picked up yet. I myself have quite a few of the PHP 5 and MySQL 5 books from various authors and every one has different things in it or show more examples than others. Also google is really awesome for finding examples others have put online to learn from and go into more detail examples from things found on php.net. The URI is the file path structure through your hosting account. /home/username/public_html/ type of format. IF your php file is located in the web root doing something like: ../ will cause a look at the folder one level up from the current file path. So if your php file that you are calling from is in the webroot and your config file is in your user folder like so: /home/username/public_html/myhappyfile.php calls to /home/username/myconfigfile.php THEN include('../myconfigfile.php'); placed within myhappyfile.php will correctly link to your config file. BUT if your config folder is located in a subfolder off your username folder then ../ will not find it. Instead what I do is create a new Definition and point to the file I need OR make sure I link properly using ../myconfig.php method, so that it doesn't matter what site I put my files into as long as I put all the files in the correct places my script will find them. IF you are going to hardcode the exact path /home/username/config.php THEN I would create a new definition and use that in my files this way I only have to update in one line instead of all over my files where I use that path. The username will be different in each site you put your files in and I don't know of a variable in php that holds that information like you would find in windows that would auto inject that information into your scripts. Edit: If you are using a subfolder located off of the folder one level up from the current file then do the following: current file: myfile.php which is located: /home/username/public_html and links to config.php which is located: /home/username/subfolder1/config.php Use the following: include('../subfolder1/config.php'); That goes one level up and then one level down into a specific folder pointing to a specific file within that folder.
  6. If you don't know what the URI is for your site and don't know where to look, create a new php file and put only the following into it. <?php phpinfo(); ?> Save the file, name it something like info.php. Then use an FTP software and upload that file to the webroot of your site. Then open that file in your browser. It will give you a listing of your PHP setup for your domain and the server. It will give you much detail on modules installed into php, folder paths and all sorts of information. It will also tell you the names of variables and what they contain such as the URI of your site, file path to the file you just opened in your browser and a lot of extra information about settings of php. IF your php installation running on your webhost is setup in such a way that file may also tell you information about Apache itself and where all the behind the scenes configuration files are located. Most hosts don't have php running in a way that shows that information but some do, if you are lucky to have such a host then you will be presented with information that is really interesting but which you more than likely will never have access to actually do anything with or be able to change. Though it is interesting to look and see what settings are set or not. For safety once you have looked at this information you should either delete this file off your site OR change the chmod settings of the file to 600 instead of 644 OR place it into a new subfolder which you can disable once you are done looking at it. It maybe interesting for you to create this file but add user login access to it so those that do not have the password never see the output. I did this on one of these files for one of my sites, but I kept forgetting the password so I just deleted the file and reupload it whenever I need access to this information then delete it when I am done. If you leave it on your site, sooner or later someone may discover it and use the information to hack your site, send bulk spam email from your site or turn your site into a bot that hacks visitors computers and turns them into bots for sending spam emails or worse. That is why I never leave my phpinfo files on my sites or without being locked down so it is not available to be used when I am not using it myself.
  7. URI is the file path to the webroot. In your URI above you have www.domainname.com that is the URL to the webroot. URI is the file path so in linux based servers that use cpanel the base_uri should be something like /home/username/public_html some use /home/username/www The public_html folder is a REAL folder that contains all the files where the www version is what is called a symbolic link which is a shortcut of sorts that points to the public_html folder. Technically there is no www folder but in reality it doesn't matter you can use either one but I personally choose to use public_html since that is the actual folder itself. All you are doing with defining the URL, BASE_URI, MYSQL is creating shortcuts that point to those locations within your code. Instead of having to replace each instance in all your files for your site you just use one of those "shortcuts" instead of writing out those locations anytime you need to point to that location in your code. This way if something changes, you move to a new host, you change a folder name or whatever maybe the case then you are just changing ONE line which then automatically updates through out your entire site. Though if you don't use those "links" in your code then you have to manually change each line to match what it should be. Just saves time and easier to maintain your code.
  8. Make sure you rename the path so it is lowercase too.
  9. You have header("Location: $url"); Try this header("Location: ".$url);
  10. Is the redirect actually occurring? You are calling headers.php at the top of this file you embedded above, unless ob_end_clean function counteracts the headers already called error you may not be redirecting in the failure ELSE statement. What is in your index.php file? The file you are redirecting to. FYI: I would suggest naming files with lowercase letters 100%, some servers have problems with camel case names plus how many pages on sites out there do you see camel case names in url?
  11. Also what version of PHP 5 are you using? 5.2 or 5.3 ?
  12. Does this directory exist on your site --> BASE_URL . 'Members/home.php'; You have a capital M in members. Is the folder named Members OR members. In unix/linux based filesystems names are case sensitive, though depends how the server is setup. I would echo that out the BASE_URL may not have the trailing slash so that may also be the cause of the 404 error.
  13. I just finished the content chapters in the first part of the book. I have just made it to page 136, Using Paypal. When I left click on the links in view_pdf.php it opens acrobat ready in my browser. I wonder if there is away to open a download save as dialog box instead of acrobat reader? Yes, I can right click and save as but is there a way to force that save dialogue popup on left click?
  14. The CONFIG file is located in the "includes folder".......do I need to include the "include folder" when pointing to a file in the same folder? ------------------------------ That depends on where you are linking the file from. I am in the process of creating a modern CMS and with CMS's the core index.php file is being used as a conduit to load and pass information off to the other files within the CMS. In this case I have a config file included in the main index.php file and since this file is also loading all the other files I don't need to reinclude the config file into all the other files because they inherit that information from the index.php file. If you are working with files that are stand alone and don't know about other files or locations then you need to include the path to the axillary files. Even though you have defined the BASE_URI with the webroot of your site you can't just use that in your files without the files themselves knowing about this definition. In most cases you would indeed link to a file using the full path. Though once you initially link the config file, using include or require or require_once then you can in future link to files by starting the path off with BASE_URI. This saved typing and auto changes based off of ONE definition which when changed updates ALL the files so they point to the correct location. Long example but short answer is it depends on how your web application is designed and Where these files are being called from. If they are standalone files that are not being called through a proxy file of some sort, like I mentioned how my CMS works above, then you can just do something like: include('nameofFile.php'); If the file calling the above file is in the same folder, this would work. But if you have a directory structure like: webroot | folder1 - folder2 | | file1.php file2.php file1.php and file2.php don't know about each other and the filesystem doesn't know to tell PHP these two files exist, so you need to tell them. If you do something like: webroot | index.php folder1 | file1.php file2.php and index.php loads file1.php AND file1.php loads file2.php It may work where you include or require file2.php from file1.php like: include('file2.php'); BUT It is "safer" to code the entire path either through harcode the whole URI path OR symbolic link or definition like Larry uses in the config files in the book. But that can come down to style I guess. I just find it safer and always works to code the entire path to the file when including it. My thoughts, take what works for you and leave the rest.
  15. define ('BASE_URI', '/path/to/webroot'); <-- file path to local web root OR web root on server wherever you are placing the site online or on intranet testing environment define ('BASE_URL', 'www.samplesite.com'); <-- web URL to web root of site. This could be a testing environment OR website hosted online. define ('PDFS_DIR', BASE_URI . '/includeds/pdfs/'); <-- This is location to the folder your PDF files will be saved to when uploaded define ('MYSQL', BASE_URI', '/includes/mysql.inc.php'); <-- You have a comma where there should be a period and a closing paren without an opening one. Should be: define ('MYSQL', BASE_URI.'/includes/mysql.inc.php'); <-- instead of using the BASE_URI here I just hardcode the entire path to the MySQL config file. What is being done here is a short hand of sorts, instead of typing out the base URI path it is being taken from the BASE_URI definition and then the includes folder with file is being added to it.
  16. I looked at the table with my IDE and it shows --> ' ��Y���_���}�5=���jQQf)�q����� ' Bunch of squares and lowercase letters and special characters.. So I guess it is working correctly and somehow phpMyAdmin doesn't show that version but instead the varchar version.
  17. What should the password look like when stored in the database? Mine is in this format: cdaf5910b0c01bd05fcfb2e87def350e3dd9caec6a51516629c771d9bb8ffaef The database tables and password functions are taken directly out of the book I am using a testing environment on windows XP Pro SP3. Apache 2.2.17 MySQL 5.1.56 community PHP 5.2.17 Though my real host has older versions of PHP and MySQL but I am only working with the code from the book on my testing environment for learning purposes. My testing enviornment has mysqli installed but my real host does not so I will have to use the mysql form of calling the database. The database table for the password is in format varbinary and I am using phpMyAdmin to look at the database.
  18. I found out from my host that they do not offer mysqli php extension except on their dedicated servers, where you can install anything you want but at a premium price of course. How much of a deal is it to use the older mysql calls in place of the mysqli database calls and what if any performance hit will my applications take? I know there will be a bit more code needed with mysql calls where mysqli are more integrated needing less code to do similar things. Will it be a big deal to convert the two demo sites to use the older mysql calls instead?
  19. I have used dreamhost and they are good host, they do NOT use cpanel so if you want or need that specific interface then hostgator maybe a better choice. DH uses a custom interface and utilities and do not have ioncube loaders but it is possible to use ioncube through custom installation in your webdirectory cgi-bin and entries in htaccess file for sitewide use or just specific folders. They do NOT support any customizations and wont help you. Their instructions on their site for how to install things like ioncube is a bit out of date and may or may not work without additional fooling around. My current host, hostduplex.com has everything included in their hosting. Though they are extremely security conscious and you have to do some customization to make php work the way you would need it, like installing your own php.ini file and customizing it how you need and adding a line into your htaccess to point to your custom php.ini file. You have to do that for ALL your sites hosted with them or you use their default php.ini which is not going to work with most things you would want to use or do. They do have cpanel though and allow for reseller accounts which gives you ability to setup sites in their own space instead of sharing one web root and setting up addon domains with in that one location. Personally I don't like shared hosting this way, where all sites off of one web folder but that is how most hosts like hostgator work unless you upgrade to a reseller account. They are similar pricing to hostgator, the basic accounts are just regular shared hosting though. They maybe willing to work something out with you if you need something that is not included on their plan pages. Dreamhost, also uses their own custom database installations where localhost is NOT an option instead they use a custom url for each of your databases. It is suppose to be more secure that way but I don't know about that, it is sort of a pia to set them up and connect your scripts to the DB's though. At least in my opinion, have a few hoops to jump through and you can't quickly make changes like a normal cPanel host can. Setting up email is a bit laborous through DH where cpanel I can do it in seconds. 1&1 is another host that uses custom control panel but unlike DH I can't recommend anything from 1&1. My personal experience with them is less than favorable. Bluehost is good as well but I wouldn't use them for every site you have, bigger sites I wouldn't personally put at bluehost. For small sites that you want to get up quickly without much bother I would go with the babycrock account at hostgator. You are not going to be able to get a huge amount of traffic to the site with their smaller hosting before they disable the account and force you to upgrade so if it is a site you plan on doing any serious traffic with I would upgrade to a larger plan. Hosting costs range from 5.00 to 25.00 per month with the smaller priced hosting all your sites are going to be in subfolders off of ONE account, versus reseller hosting where you can setup each site in their own space with their own control panel via WHM or similar controls. The second common control panel out there is plesk, you will not have to pay anything extra for that where cPanel is an extra fee due to their licensing scheme. Plesk takes a bit to get used to but you can do the samethings whether plesk or cPanel they are just labeled different and in different places. I mainly recommend three hosts, due to my own personal experience. hostduplex.com -- they have many plans and price ranges and allow you to grow, they use virtualized hosting space where accounts are in their own memory space which means all their hosting is shared but if one site goes down it doesn't take out the whole server or mess with any other sites on the server. You do have to do some customization with your own php.ini file though to make php work right though mod_rewrite and most other modules you need or want are installed by default into server so you are good to go from that standpoint. Support is best I have ever seen, anywhere for hosting. hostgator -- I have never used their shared basic plans I have always used either their reseller plan or dedicated server with them. Support is good, tier one is basically canned responses though. Live chat you get good responses and help. dreamhost -- good host. I had personal issue with way some of their stuff is setup and handled but overall I used them for close to two years. There is no way to migrate from them automatically though so if you plan to migrate your sites from this host at some point I would go with one of the other two. I can not recommend anything from godaddy in way of their hosting, in fact many scripts that work in regular hosts will NOT work on godaddy and you can't really do much customization or have really any control with how things work there. My personal view is godaddy hosting is a addon front to get you to use their services and buy domains from them, and isn't really meant for database driven dynamic websites. My personal view there but many agree with me. Also 1and1 hosting I would strongly advise to stay away from. I have hosted with them and purchased domains from them but my own personal experience was far far far from pleasant experience and they control and wont easily allow you to move domains from them. Also their hosting is not cpanel, a custom version of plesk or was, which does not allow for many things cpanel can do in seconds. Waiting for 30 minutes to 2 hours to setup ONE email address where cpanel it is instant for example. Those are my own personal recommendations but if you search you will find hundreds of hosts out there, many are small one person setups where they are just sharing their own hosting space for a fee to subsidize their own hosting. Look for support that offers live chat and bonus if have 800# or equivalent phone support, some charge for that the really good ones don't.
  20. I would contact your host and ask them to check your site and make sure it is configured correctly. Just looking and seeing if mod_rewrite is turned on doesn't really check if there is a config issue somewhere. Any solid host will go that extra step and verify this when you ask. My host actually goes so far as creating files and folders in the sites space to verify things are working. if you create a php file with just phpinfo() and run it from within your site is php running as CGI or apache module? You should be able to see if mod_rewrite module shows up in the loaded modules but this does depend on how your host is configured. If all you ever get back from support is canned responses I would consider moving to a new host but that's just me. I would though make sure that your host does check out your account, there could be something screwy that is impacting that domain. I used to have an account at dreamhost and they had a utility that you could manually run and it would check for any issues but that wasn't always 100% either, best to have a real person go in and check things over. If they wont, or you just get canned responses... My current host has a 800 number I can call, support tickets via email and live online chat. Support is critical when it comes to your sites, consider switching if you don't get any.
  21. After looking at the htaccess code I see what is suppose to be happening and that the actual php files are not in the shop folder, if that folder exists. I am going to go back to reading the book, ignore my post above it doesn't apply to this. If both sites have same hosting and are on same exact server then I wouldn't think it is a hosting config issue. You may want to verify that the sites are on same server, sometimes sites are not even in same hosting plan within cpanel. I would rename the htaccess file on site one and copy the htaccess file from site two over and see if that works. If so then there maybe some funkiness with the htaccess file on site one, corrupted or not working due to uploaded in wrong format binary vs ascii etc... OR junk characters inserted from your editor or something.
  22. Question. Do the files you are rewriting the URL to actually exist and are readable by browsers? I have not gotten that far into the book yet but today I have been doing a lot of htaccess and mod_rewrite stuff. Looking at both live examples it looks like the second example has same code as first site, have you done a line by line comparison in your editors or IDE to see what the actual differences are? To me, not know any more than what you posted and looking at the results on your sites, it seems that the actual files sales.php, and whatever you are rewriting to for coffee, goodies don't actually exist or are not readable via browser. Second Site: http://www.acmaine.com/shop/sales/ <-- WORKS http://www.acmaine.com/shop/sales.php <-- WORKS First Site: http://www.buythebead.com/shop/sales/ <-- NO WORK http://www.buythebead.com/shop/sales.php <-- NO WORK That is why I am thinking there is a file placement or permissions issue.
  23. In my php.ini file on my testing environment I have: error_reporting = E_ALL & ~E_NOTICE I don't see anywhere I have specific STRICT setting for errors.
  24. Thanks for responding. I set the time zone in the index.php file at the time zone error went away. I am just using the code from the beginning of the Second Section of the book the Paypal project. I don't see any time or date BUT there is a custom error handler which does get time/date from the system so I guess that is where that error is triggered from. It makes sense now. Thanks. P.S. I do not know if error handling is set to strict. This is what Larry has for setting the error handler "set_error_handler('my_error_handler');" then the function outputs number of the error, error message, file error occured in, line number of error and then all the set variables.
  25. I found something strange during a debug session for footer.html upto page 71 in the second part of the book where the basics of the index.php file is being created. I am building this on my testing environment: Win XP PRO SP3 Vertrigo Server Apache 2.0.64 PHP 5.2.7 MySQL 5.0.51a From the book pg 69 end of part 3 and begin of part 4 if(isset($_SESSION['user_admin'])) { echo '<div class="title"> ... .. snipit .. </ul> '; } <--- Closes if user admin IF statement } else { during my handcoding from the book I left out the closing bracket for the IS ADMIN IF statement so the above looked like if(isset($_SESSION['user_admin'])) { echo '<div class="title"> ... .. snipit .. </ul> '; } else { I was getting THIS ERROR An error occurred in script 'D:\_intranet\home\resources\ecom1\includes\footer.html' on line 42: include() [function.include]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for '-5.0/DST' instead It was hell tracking down the issue but I figured it out. As I see it, at this stage in the code there is NO reference to any time or date functions. Why would this error be thrown? Once I discovered the missing bracket I fixed it and the error above went away. I guess this is more a novelty than anything but I am curious why a date time formatting error? Is it reading from the database the date fields and PHP doesn't know what format the time zone is suppose to be? I dunno, found this odd and posting what I experienced. Dunno. Thanks.
×
×
  • Create New...