Jump to content
Larry Ullman's Book Forums

Terry

Members
  • Posts

    87
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by Terry

  1. I understand now. In the redirect, this part %{HTTP_HOST} Needs to be replaced with titanicraisins.c8.hostexcellence.com The reason is %{HTTP_HOST} is your website URL titanicraisins.com That SHOULD work, but you say that this does not. I would contact your host and tell them the issue and see if they can suggest something. Some hosts require SSL accessed files to be in a special folder, some hosts do not. I can't help anymore at this stage because this should be working, either there is more to this than you are sharing more lines and redirects in the htaccess or you need to place checkout.php and others into a special folder or there is not something configured right somewhere with your account. I don't know, all I can suggest at this stage is to contact your host.
  2. What browser are you using? I misread your post, I thought you were trying to get the URL to be your domain and not the shared hosting SSL URL. I visited the link in your post in FF4 and IE8 and it worked for me and was the shared SSL url. If it isn't for you possibly your cache needs to be cleared? Edit: For me in the browsers it is Blue not Green, but the LOCK is shown in IE but not in FF4 but FF4 I think shows it different. When I hover my mouse over the blue portion of the URL I get a popup that it is verified.
  3. If you are using a shared SSL, the one provided by your host free of charge versus using your own SSL certificate you will get warnings and so will your visitors because the SSL is not tied specifically to your domain. Shared SSL's CAN'T be tied to a domain it is tied I believe to the server itself? Not sure. If you get your own SSL specific to your domain then you also won't have to monkey with the code to make it work with the shared SSL url.
  4. Reading through the code example you posted again, I have a tip for you that I discovered when debugging my current project. <?php function bar(){ $f_a = 'a'; echo '"f_a" in BAR is: ' . $f_a . '<br />'; } bar(); // <-- example on how to call the above function ?> I simplified the code to make it easier to describe the issue. In the above example the function outputs a string within the function itself, with $f_a being dynamically added and the value is "a". Lets assume that you are creating a dynamic page and calling this function to auto propigate a section of a page and this is to be inserted between a DIV tag formatted by CSS. <div class="class_1"> <?php bar(); ?> </div> You would assume that the ECHO of the function would fall within the DIV correct? Will you would be wrong. Why? In the layout of the function code the echo is not specifically being returned instead it is just outputted to the browser. It comes down to order of operation and what I was talking about above with functions not knowing anything about what is outside of itself. I may not be explaining this too well but I will try to layout my point below. 1: You have a function that echo's a string to the browser 2: You have a HTML page formatted by CSS and purpose is to format the string echoe'd from the function When you specifically RETURN a value you are essentially saying go back to the exact place where the function was called. So in the above example it would be go back to the specific place where bar(); is located. Like bar() is a bookmark or place holder. BUT when you do not do a specific RETURN from a function and in the specific example above I did not you are saying, output the string to the browser NOW. The problem is you aren't telling it where to output the string so it just does it as if it were a separate page. The browser see's the new outputted string and it sees the CSS formatted sections of the page but the new string isn't related to the formatted section so it just places it at the top somewhere. Now depending on your CSS and the HTML in the page you will get weird result and a broken template. The string may not be displayed at the top of the page it could be anywhere on the page depending on the browser. This is why I say you should return specifically any data you want back out from a function. Though global variables are different and have nothing to do with display I still think it is a good idea and this is maybe a poor example but it is one specific example of why I think so. To actually get the above example to work as expected you would want to do something like this with the function: <?php function bar(){ $f_a = 'a'; $new_string = '"f_a" in BAR is: ' . $f_a . '<br />'; Return $new_string; } ?> Then in the page do this: <div class="class_1"> <?php echo bar(); ?> </div>
  5. What I discovered when switching from mysql to mysqli is that when you use mysqli_connect it handles selecting database for you as seen with the last parameter DB_NAME. $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); With the old style mysql_connect you have to add a separate call to select the database. $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD); $dbSelect = mysql_select_db(DB_NAME, $dbc); I have never seen a function defined within a function before. Not sure why you would want to do that. With PHP all variables defined within a function are local variables UNLESS specifically stated as global which then allows that variable to be used outside the function. Depending on how you do this it can be a security issue and shouldn't be a regular coding practice. Functions are isolated modules, a room with no windows or doors so it can't know what is outside of itself UNLESS you tell it. Declaring a variable as global within a function connects that variable to global variable with same name outside of itself OR creates a new global variable if one doesn't exist. For example: Global $seeMe; <-- New global variable $seeMe = (string)"I am a String Variable"; Function my_func($hi){ echo $seeMe; <-- variable used within function, isolated variable and value is empty. } As you found out $seeMe is not accessible within a function because it has no clue about anything outside of itself UNLESS you tell it which in the above example I did not. Global $seeMe; <-- New global variable $seeMe = (string)"I am a String Variable"; Function my_func($hi){ Global $seeMe; <-- NOW tells the function of the existence of a new variable which is GLOBAL defined and in this case there is an existing variable in the GLOBAL scope so my_func() now knows about it and can use it. echo $seeMe; <-- GLOBAL variable used within function and value is "I am a String Variable"; } In your code you have a function within a function and neither one knows anything about the other one. Instead of declaring functions inside of each other I create a separate file with all my functions and then just call the function I need within my code. If there is only one value as a result of the functions operation you can set that return value as a Global Variable BUT it is safer to specifically return the result to the specific code that called the function and not have some GLOBAL variable floating around out there. Comes down to personal preference and can save on coding but still is tighter to specifically lay down a road for each variable, section of code and force it to follow that paved path then have free range code and variables floating around all over. Depends on complexity of the program but having paved paths or roads for your code can help with debugging too.
  6. Now if you wanted to test and see if I am correct You could do something like this: $i = 0; while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { $i++; echo "Loop: ".$i."<br />row[0] = ".$row[0]."<br />row[1] = ".$row[1]."<br />----<br /><br />"; echo "<option value=\"$row[0]\">$row[1]</option>\n"; } This way you can watch as the information is taken out of the database and inserted into the array and see what is there. EDIT: actually the database has already been queried at this point and the WHILE is taking the array $r and extracting individual rows and inserting into a NEW array called $row which consists of 2 elements id and category which are placed individually into $row's FIRST element which is $row[0] and SECOND element which is $row[1].
  7. LOOP 1 $row[0] == 1 $row[1] == Dark Roast <option value="1">Dark Roast</option> Loop 2 $row[0] == 2 $row[1] == Kona <option value="2">Kona</option> Loop 3 $row[0] == 3 $row[1] == Original Blend <option value="3">Original Blend</option> When it is finished you have a drop down menu with THREE options Dark Roast Kona Original Blend Does this make sense now?
  8. In your get_password_hash function are you defining $dbc as global? global $dbc; I updated a project of mine from mysql to mysqli and I got a very similar error to what you are getting. I needed to switch the position of $dbc so that the mysqli_connect call came first. But in your error it shows that it is also NULL which to me tells me that there is NO mysqli database connection call contained inside of $dbc. So is $dbc created correctly AND is $dbc being referenced from this function of yours so it is being seen? From mysql.inc.php file from EX1. $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); AND inside both the functions in this file $dbc is being called by global variable OR if you don't I can see you getting that error. - T
  9. while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\">$row[1]</option>\n"; } The above is the loop that creates the drop down menu for the category. $row[0] is category id $row[1] is category title What it is doing is grabbing each row for the category and echoing the individual row info on each loop through. So like I said above on the first loop through $row[0] would be 1 then next would be 2 then three OR whatever the actual data is in the database table columns. It could be 54, 55, 56 or whatever, doesn't matter, whatever the next value is it is displayed. $row[1] on first loop is Dark Roast, then second it is Kona then third it is Original Blend. This line echo "<option value=\"$row[0]\">$row[1]</option>\n"; Is the options for the drop down menu and it is being dynamically populated with the data from the database. The data is inserted from an array that is populated by the WHILE statement. Each loop through $row[0] and $row[1] have different data in it.
  10. $row is an array. Looking at the code you copied in it looks like an array is being created with two elements or place holders that contain the row number and contents of that table column in your image. Then it is echo'd out in the form in a loop to bring out all the rows for that form. First loop it brings out "Dark Roast" and I assume '1' for the item number then second loop it brings out "Kona" and I assume '2' for the item number... I am just going off of what you posted, I haven't looked at the book before posting. - T
  11. I agree with Larry when it comes to hosting and registering domain names they should be seperate. Reason is you are in control and if your host goes belly up you can redirect the domain to a new host in seconds without having to wait for a 3rd party to do something. I used to bundle my hosting and domains but having similar experiences as abigail over the years I do not do that anymore. Also it is good to have your websites with companies that just do hosting. Many hosts also offer various other services but usually through 3rd parties and they remain focused on one thing, HOSTING. Samething for domain registrars, though many also offer hosting their main thing is domain registration. I would not advise to bundle with one company no matter what their prices are because of situations where having all eggs in one basket can and will eventually come back to cause issues for you, maybe not now but later down the road at least from my own personal experience. I use namecheap as my registrar I used to use gd, dreamhost, and several others including hostgator but over the years I have moved domains to consolidate under namecheap but it is probably good to have more than one registrar I just found issues of one kind or another with other ones I used. It is also a good idea to have more than one host as your sites develop and you build up more sites having them all under on roof wouldn't take a whole lot to completely have your business literally vanish in seconds. my 2 cents on that.
  12. I edited my posts above a dozen times to make corrections. I am now royally confused about this. LOL I can't say there are no errors or bugs in code samples or what I typed above. It should be enough to start with and help you understand the process. Please ask questions because I am sort of out of steam on it. LOL In my testing environment I deleted the htdocs folder entirely and placed my website files on a seperate hard drive and then told apache where those are at and what web url to use to access them. You should be able to use htaccess files in your testing environment as well, if not then you need to reconfigure your server software. I also customized a php.ini file in my local sites that puts php errors in the folder the file that generated those errors is located. That is a php configuration not apache, there maybe a way to get apache log files to output in each local sites web root as well but I don't know how to do that and would have to work with special constants which I am not sure apache is setup for, I never looked. To do that with PHP you need to either customize htaccess file OR create a custom php.ini file for each site. I have 30 or so sites setup in my testing enviornment so I can't really use a common config file except for basic default settings, but that is more advanced than I care to go into. Thanks.
  13. Everything in the html folder is the actual example 2 WEB ROOT. Larry just has things organized neatly in the ZIP files. Extract the contents of the html folder to your cp folder, which is your web root. The setup I use in my testing environment is: home | ex2 | public_html Where home is localhost and ex2 is example 2 site. I then tell apache to use www.ex2.lcl as the web root for this project so when I type in www.ex2.lcl into my web browser it opens d:\home\ex2\public_html home also would be considered htdocs folder or the folder localhost is mapped to. So I can do something like this: home ________|________________________ | | | | ex1 ex2 site3 site4 | | ___________|_____________ | | | includes public_html mysql.inc.php ex2\html would go in public_html folder, mysql.inc.php is inside ex2 folder and my other includes could go in the includes sub folder inside the ex2 folder. So ex2, is outside the web accessible folder of public_html. Though technically localhost in this example can access it but I never use localhost myself so it doesn't matter. In the ZIP file it is layed out like ex2 __________|______________________________________ | | | | | private html sql.sql README.txt mysql.inc.php ex2 is the parent folder that the ex2 web root sits inside of, the above layout this is the html folder. so the example site 2 php files and website files are located in the html folder. mysql.inc.php is the mysql connection file, I put this inside of a conn folder myself but as is, it is sitting outside of the web root so it is ok to leave it there. Now to correlate the above to your setup it would be like this: I do not know the actual folders so I am going to guess. //localhost/htdocs/cp c:\xamp\htdocs\cp htdocs <-- localhost | cp When you type localhost into your browser it should open htdocs folder. If it opens XAMP then your server is setup wrong, XAMP I assume would be where apache, php, mysql folders are located. localhost should NEVER have access to that folder. htdocs woould be in testing environment world document root and also web root. IN LIVE web server, hosted on internet it is setup different where there is a parent folder on top of htdocs that is NOT accessible by web at all. To mimic that, you just add a folder between htdocs and cp then change apache's document root to that second folder, this way you can have multiple sites running off same localhost within same folder structure. Though technically they can be anywhere.
  14. In a cPanel based host this is how the web directory structure is setup. home <-- Users, which would be you, your scripts etc... do NOT have access to this folder. | username <-- This is the base folder for your website, it is NOT web accessible, in non-reseller hosting this one user would control ALL your sites. | public_html <-- this is web accessible folder, in non-reseller hosting ALL your sites would be located in sub folders off of this folder. I do NOT use XAMPP or preinstallers that setup everything for you, I used to but they can't handle custom installs with multiple instances of php, mysql etc etc... The instructions below are for adjusting Apache via httpd.conf and/or httpd-vhosts.conf files. These maybe named different in your install. To get httpd.conf setup to use multiple folders where each folder is a new project you would put the following in httpd.conf OR vhosts.conf or httpd-vhosts.conf. I do NOT know what file your setup uses for the virtual hosts but there should be a link or something in your control panel XAMP uses to give you access to the correct location. You can also find it manually by going into where ever apache is installed on your hard drive and looking through the apache\conf folder for httpd.conf and scroll towards the bottom of the file somewhere and see if there is a section that starts off with # # Virtual Hosts # # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.2/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # Use name-based virtual hosting. # #NameVirtualHost *:80 If you do not see this then there maybe a link that looks similar to # Virtual hosts Include conf/extra/httpd-vhosts.conf Find this file if this link exists in httpd.conf and open it in notepad or something similar, do not use wordpad as it adds hidden junk characters to the file. Now my setup is going to be a little different to yours, so make changes based on your setup. I will explain line by line best I can. I am going to leave out the commented sections to save space, so pay attention to your file and where these lines are located in it. To be safe you should save a unmodified copy if this file so if what you change doesn't work you can revert back to a working copy. You will need to restart apache once you make the changes or it wont work until you do. NameVirtualHost 127.0.0.1:80 <-- This line defaults at *:80 this makes ALL ip addresses accessible to your testing server on port 80. I hardcode the localhost IP address instead of leaving it open but it will work either way. <VirtualHost 127.0.0.1:80> <-- Tells Apache this is a new virtual host and what IP and Port it is on, default is *:80 DocumentRoot D:\htdocs\home <-- This sets document root for local host, this is a windows file sctructure, notice no closing slash at end ServerName localhost <-- This is the NAME of the virtual host, in this case it is localhost </VirtualHost> If you type localhost OR it's ip address into your web browser it will now open to the DocumentRoot folder "home" Change the folder above to whatever your base root folder is. If this is already set in your XAMP installation and you are happy with it, don't change it. Next I will show you redirects or multiple URL's to access ONE folder, which would be your project folder. Under the lines above enter the following, changing to fit your setup. <VirtualHost 127.0.0.1:80> ServerName ex2 <-- Name of the URL you type in the web browser Redirect permanent "/" "http://www.ex2.lcl/" <-- Actual URL that the ServerName will go to, this has NOT been setup yet, but when it is it will work. </VirtualHost> <VirtualHost 127.0.0.1:80> ServerName ex2.lcl Redirect permanent "/" "http://www.ex2.lcl/" </VirtualHost> I setup ex2 and ex2.lcl to both redirect to www.ex2.lcl If you want seperate ex2.lcl and www.ex2.lcl then you have to duplicate the line below. Next I setup the actual web url and folder for apache so when you type ex2 into your web browser it actually goes to the right place. The reason I put ex2 in as redirect as it saves typing, you don't have to put that in if you don't want it. <VirtualHost 127.0.0.1:80> ServerAdmin administrator@ex2.lcl <-- Email address for server admin, I always add this in though I don't think it needs to be there technically. DocumentRoot D:\htdocs\home\ex2\public_html <-- DocumentRoot, webroot for this project. This folder structure MUST exist ServerName www.ex2.lcl <-- ServerName is the actual web address for this site, must put here what you would type in web browser ErrorLog logs/ex2-error_log.txt <-- This is Apache error log output for this site, you do not need this here. It is NOT php errors specifically it is ALL errors apache records for this site. This is NOT put in the project folder, it is put in logs folder within apache's main install folder. CustomLog logs/ex2-access_log common <-- This is similar to the error log above. Read apache manual about this log. </VirtualHost> Now if you want both WWW and NON www versions of web URL working for same project site then you need to duplicate the lines above but change the ServerName to ex2.lcl and remove the redirect lines to ex2.lcl. <VirtualHost 127.0.0.1:80> ServerAdmin administrator@ex2.lcl DocumentRoot D:\htdocs\home\ex2\public_html ServerName ex2.lcl ErrorLog logs/ex2-error_log.txt CustomLog logs/ex2-access_log common </VirtualHost> <VirtualHost 127.0.0.1:80> ServerAdmin administrator@ex2.lcl DocumentRoot D:\htdocs\home\ex2\public_html ServerName www.ex2.lcl ErrorLog logs/ex2-error_log.txt CustomLog logs/ex2-access_log common </VirtualHost> -- This code makes ex2.lcl AND www.ex2.lcl go to the same folder which would open the same site. In addition to adding those lines into Apaches VirtualHost section you must add the URL's to the windows hosts file or no redirecting will work at all. I use LCL extension for my testing server though you can use any extension you want, make up a new one but I would not use .net, .com. .org or real extensions or you will never be able to access those LIVE sites from your computer. # windows HOSTS file #------------------------ 127.0.0.1 ex2 127.0.0.1 ex2.lcl 127.0.0.1 www.ex2.lcl Restart apache and your new site should showup in your browsers. This only works on THE computer you set the above up on. Now to get a new project working you just duplicate everything above and change names and url to whatever the new site will be, except the localhost document root, that is a single entry one time only. You can have as many URL's pointing to as many folders as you want, the folders can be located ANYWHERE on any accessible hard drive, flash drive, cdrom etc... Putting it together: # WWW and non www go to same URL, the WWW version # typing ex2.lcl will ALWAYS redirect to www.ex2.lcl # so there is NO non WWW version of site. NameVirtualHost 127.0.0.1:80 <VirtualHost 127.0.0.1:80> DocumentRoot D:\htdocs\home ServerName localhost </VirtualHost> <VirtualHost 127.0.0.1:80> ServerName ex2 Redirect permanent "/" "http://www.ex2.lcl/" </VirtualHost> <VirtualHost 127.0.0.1:80> ServerName ex2.lcl Redirect permanent "/" "http://www.ex2.lcl/" </VirtualHost> <VirtualHost 127.0.0.1:80> ServerAdmin administrator@ex2.lcl DocumentRoot D:\htdocs\home\ex2\public_html ServerName www.ex2.lcl ErrorLog logs/ex2-error_log.txt CustomLog logs/ex2-access_log common </VirtualHost> # WWW and non www go to same folder # typing ex2.lcl will open the example 2 website # There is BOTH WWW and NON WWW version of site. NameVirtualHost 127.0.0.1:80 <VirtualHost 127.0.0.1:80> DocumentRoot D:\htdocs\home ServerName localhost </VirtualHost> <VirtualHost 127.0.0.1:80> ServerName ex2 Redirect permanent "/" "http://www.ex2.lcl/" </VirtualHost> <VirtualHost 127.0.0.1:80> ServerAdmin administrator@ex2.lcl DocumentRoot D:\htdocs\home\ex2\public_html ServerName ex2.lcl ErrorLog logs/ex2-error_log.txt CustomLog logs/ex2-access_log common </VirtualHost> <VirtualHost 127.0.0.1:80> ServerAdmin administrator@ex2.lcl DocumentRoot D:\htdocs\home\ex2\public_html ServerName www.ex2.lcl ErrorLog logs/ex2-error_log.txt CustomLog logs/ex2-access_log common </VirtualHost>
  15. Actually I realize now what I was meaning to say with this thread.... I did not mean QUIT I mean EXIT.. I program several languages and recently have been using AutoIT3 which is a basic like language I use to create windows applications, mainly little tools I create to help me do things easier. What I meant to say was what is the different between exit() and exit because exit() didn't seem to work well for me for some reason... Geez... Anyway through research I figured out what the various methods of calling exit are and how they work... (sigh). I am usually operating on too many hours of sleep loss, over worked and sometimes it catches up to me.
  16. My host has a secured php.ini configuration as well, the only way around this is to either use your own php.ini file that matches your version of php OR switch to a different host. Safe mode is like training wheels for php, it should only ever be used in a testing situation when making sure php is working correctly it should NEVER be on in a production environment. Most things we would use php for won't work in safe mode. Also register globals should be turned off in the php.ini file as well, my host has it turned on. Fortunately I was able to figure out how to get a copy of php.ini running on my host and changed a lot of the settings so they work how I need them to and then configured my htaccess file to use my version of the php.ini file. Otherwise I would have had to go to php.net and download the closest if not exact version my host uses for php and start with the default php.ini file. Unfortunately the version of php my host uses isn't available any longer at php.net and there are some minor differences to php.ini in later versions. You can also set individual parameters inside of htaccess file but I have never really messed with that much.
  17. Is mysqli installed in php running on your host? I have this problem so I need to either move to a different host or rewrite all the database connection code to use mysql. I think I will upgrade to a VPS on a different host soon but until then I can't use any of the mysqli stuff except on my testing environment.
  18. How is phpMyAdmin running, is it setup to use mysql OR mysqli? Most phpMyAdmin's I have seen use mysql not mysqli. IF you are using a testing environment for the site then go into phpmyadmin's config file and tell it to use mysqli. IF you are on a hosted site where you have root access you can change the config file there too, though sadly if you are on shared hosting you are stuck with whatever they have it set to use. That is only thing I can think of is it is mysql not mysqli. Sounds like a configuration issue or database issue of some kind if phpMyAdmin is running with mysqli.
  19. I think I am wrong about DOCUMENT_ROOT. Here is copy/paste from one of my phpinfo files on my testing environment. I first thought document root was the folder you first logged into from FTP which is /home/username for most hosts out there or with reseller account anyway where you can have each site under it's own space. But that isn't correct. I then thought it was the web root.. BUT, looking at my phpinfo output it appears that DOCUMENT_ROOT is the actual folder that the current file is located. The definition at PHP.net says it is the folder the current file is running under. So if you have 30 files in 10 different folders then you have 10 separate document roots. Joy. Definitions.. I usually just point and say I want it to do that, make it do that. LOL
  20. I have not gotten into site 2 so I can't help there. htaccess files need to be off of the web root or web accessible folder.
  21. Hmmm... I swear I saw quit(); in the book... I tried quit; and it worked.. Hmmm.. Time for medication maybe.. LOL I have never seen exit used with the () I looked it up at php.net and there are exit; exit(); and exit('some text here'); Three different ways of stopping script execution. I also did not see quit over at php.net. I have been coding a lot in AutoIT v3 which does use quit... I looked at my code in 3 of my php projects and I have used exit; LOL. Only thing I can say is I have coders hang over or something, seeing quit everywhere. LOL Ok, starting a path with " / " tells php to start at the web root and work forward from there? So if I am in a file 3 folders down and I want to include a file in the web root folder I just do include('/name_of_file.php'); I just noticed you said root... Ok, explain what root is. This is what I think it is, tell me if I am wrong. Most people do not have access to root so it would be the root of their account which would be: /home/username <--- THIS_IS_ROOT_FOLDER So... /home/username/public_html <-- THIS IS WEB ROOT, BASE_URI, Document Root Or whatever this folder is named which is the web accessible root folder, might not be public_html, could be www or something else. So if I am 3 levels deep off of the web root and I want to access a file in web root folder via absolute reference: include('/public_html/name_of_file.php'); You may want to check what exactly I am telling people cause I could be totally wrong. LOL Anyway, I am here to learn and helping out when I can, helps me learn too. Though, I may not be correct. LOL Thanks.
  22. This is how you setup a new virtual host that then becomes a stand alone web root. This folder you link to can be anywhere on any drive accessible to the computer you are using. I used to use just plain ex1 vs ex1.com or www.ex1.com the problem I ran into was testing my scripts, I really needed a full domain path so I now use .lcl as the extension which of course stands for local. Step 1: <VirtualHost 127.0.0.1:80> ServerName ex1 Redirect permanent "/" "http://www.ex1.lcl" </VirtualHost> The above redirect ex1 to www.ex1.lcl because I am lazy and don't want to type the full domain path I just want to type ex1 and it takes me to www.ex1.lcl Step 2: <VirtualHost 127.0.0.1:80> ServerAdmin someemail@localhost.lcl DocumentRoot D:\_intranet\ex1 ServerName www.ex1.lcl ErrorLog ex1-error_log.txt CustomLog ex1-access_log common </VirtualHost> Now this is the actual virtual host itself that points to hard disk D: in subfolder /_intranet that contains a folder called /ex1 http://www.ex1.lcl will now point to the /ex1 folder and that folder is NOW a web root for that URL. You must put those two code block together in the same file, whether that is in the virtual hosts section of httpd.conf or it is the virtual hosts file depends on your apache setup, I can't know this but it will be one or the other and is found out but looking in the httpd.conf file towards the bottom of the file there will either be a virtual hosts section, that is commented out OR a link to a virtual hosts file will be found. Step 3: ----------- Find and open your hosts file, found at C:\windows\system32\drivers\etc\hosts This file does NOT have an extension and should never have one. Open this file in notepad and type the following somewhere in the file, it does not matter where you place it as long as it is not commented out. 127.0.0.1 ex1 127.0.0.1 ex1.lcl 127.0.0.1 www.ex1.lcl Then save the file. You do NOT have to restart windows OR apache after you get done editing this file. You may be presented with a warning message, ignore it and save over the existing file. Notepad may not allow this. I personally use PsPad which is a free editor. If you have trouble saving over this file you can temporarily change the file permission by right clicking on the file and choosing properties then unselect read only. You operating system will not come to a crashing halt if this file is writeable, sort of a security risk but all this file does is allow you to redirect your internet enabled software from one site to another or to localhost which prevents access to a site or sites from your computer only. Once you have made the changes to the httpd.conf or auxilary file you will need to restart apache. Done setting up a virtual host. For every conceivable URL you want to access a specific local virtual host you will need to add an entry to both the hosts file AND the virtual hosts section of apache's config file. You can actually have ex1.lcl redirect to www.ex1.lcl or vice versa BUT bewarned you will never be able to access the URL you are redirecting, this causes trouble if you are testing a www vs non www version of your scripts because you could restrict yourself out of one or the other of those depending what you put in the virtual hosts. A lot of people don't know how to setup local testing environments so this should be helpful. Other things you can do also is make htaccess files work, setup php error files to show up in the folder that causes the error instead of hidden away in php's installation folders somewhere, if you have error tracking turned on. I renamed my errors file to errors_log.txt so I can double click it and it opens up in my editor. There is a lot of things you can do actually and if you have root access to your sites, you can duplicate your testing environment settings on your hosting account OR vice versa.
  23. Did you specifically setup a site within XAMP that points to that ex2 folder? So if you associated something like http://www.ex2.lcl then it opens to the ex2 folder? OR are you just using the default settings and haven't customized it yet? I was looking at this today actually in a tutorial I found in another book. EDIT: Document Root is considered to be the BASE_URI. In other words it is the starting folder that is accessible to the web browsers and any sub folder underneath it. the folder the current file is located in. There are several definitions that all mean the same thing, web root, document root, base_uri are the same. URI, some consider to be path to webroot but if you look at the context URI is usually used in it is just the file path to a location a folder or file. It does NOT have to be to a web accessible folder or file though. I noticed also that URI is interchangeably used when referencing web URL paths as well, just to add to the confusion I think. You have to pay attention to context of what the person using it is trying to explain, they may have the definition wrong OR we do... LOL EDIT: It is whatever phpinfo told you the document root is. EXACTLY typed as it says it is. The BASE_URI is the parent folder, the starting folder that is web accessible. When you type the address into your web browser that first folder that gets accessed is your BASE_URI. http://www.ex2.lcl if you had that setup in your virtual hosts file then whatever folder that is pointing to is the BASE_URI for that site. IF in your testing environment you are using the default settings with no virtual hosts setup and you have to type: Then technically whatever folder localhost itself points to is the BASE_URI but in context of the site you are working in then \ex2 is your base_uri or web root. BUT you can't just type \ex2 and that is it.. you have to type the actual file path to that folder so if it is in C:\htdocs\ex2 then you have to put that whole thing into the BASE_URI definition. The REQUEST_URI is different from URI and document root and files. Without going to look up the exact definition for you I will just explain my observation of it. REQUEST_URI is everything "AFTER" the www.yoursite.com in the URL. This could be information you are passing such as variables, session information, folder or page. It comes in handy when you need to know everything that is passed to your files without knowing exactly what is there and you already know the domain name. -------------- I do not use XAMP or any specific premade installer that puts apache, mysql, php etc... on your windows computer and sets things up for you. I used to use Vertrigo which is a different flavor of these type of software, the problem I had was when I needed a specific install of apache or php or mysql you are kind of stuck. Now I manually go to each applications website and download then install the version closest to what I need and then I manually configure the config files how I need. I do not see any difference, between doing it manually and using one of the premade softwares like XAMP except manually it gets setup how I want it. I also created a little utility that I use to start and stop Apache and MySQL, restart them and tell me if they are currently running or not. In Apache's httpd.conf file there is a section at the bottom that either links to a seperate file OR is contained within httpd.conf that allows you to setup virtual hosts. This is what you use to setup something like http://www.ex1.lcl and point that to say /ex1 folder off of your web root but the brilliance of these virtual hosts is they do not have to be inside the predefined web root XAMP or whatever sets up for you. I have mine all setup on a seperate hard drive from my operating system drive, this folder could also be on a flash usb stick if you wanted. Of course you have to have the flash stick connected to a working USB connection. The reason I said all that is when you setup a new virtual host that points to a specific folder, then THAT folder becomes the new web root for that site. I have 30 or 40 seperate web roots contained within my virtual hosts file for my installation of apache. Just typing the specific local site into my web browser takes me to that specific site. The new version of Apache the virtual hosts are located in a seperate file linked to from the httpd.conf file, they all used to be inside that one file. I think the particular premade installation software I used the creators consolidated into one file, but in the standalone apache you can download off apache's site all these things are in seperate files located in etc subfolder. Took me awhile to figure it out but I got it all working.
  24. I explain the differences between URI and URL here --> http://www.larryullman.com/forums/index.php?/topic/180-what-exactly-is-a-uri/ Basically URI is the file path to a file or folder. BASE_URI is defined as the file path to the web root. BASE_URL is defined as the URL or internet address to the web root. You actually need both BASE_URI and BASE_URL defined because when you are telling php the locations of your files and folders it is better to tell PHP where things are using the file path on the server where the URL is primarily used in php to see how files are being called, what information is being passed etc... even though technically both point to the same location there is a difference in HOW these are happening. URI and URL are two different things, even though at first glance it seems they both are doing the samething it is done differently. I am trying to come up with an analogy that describes the difference but am having a hard time of it. I guess URI could be considered the back street to the files and folders where the foundation of the files are solid in the ground the physical location, where the URL is like the yellow pages in the phone book where you look up an address and then get in your car, the web browser, and go visit the website. When you FTP your files to the webserver you are uploading to the physical hardware of the server itself, the hard drive of the server the URI of your website. The URL is visiting and displaying the files in your web browser. Though they both get you to the same place, URI is strictly meant to be referenced on the hardware itself where the URL accesses through the internet address. I don't think I did a very good job explaining and my analogies are probably wrong but it is best I can do, at least right now. Now as far as the other issues you are having, I have some news that may not be too happy for you. The hosting service you have chosen is notorious for not working correctly with most things one would want to do with more advanced things like php and mysql. I think that particular host is more suited for static html websites than any dynamic sites, especially a website designed with a shopping cart integrated into it. All I can say is that people that have used your particular host that I have personally talked with or read their experiences online, once they moved to a new host things that never worked just magically started working. It has to do with how they have customized and locked down their services, which by nature prevents what I would call "normal" operation of things from working. I can't really comment further on it other than clients I have had that use that service I required them to move their sites somewhere else before I would touch them. That might be a bit harsh or disconcerting but it is really hard to make a lot of things work if at all, with that particular host. You might be able to find a way but I can't really help with that or give suggestion. If you use what is in the book and it should work but it doesn't, and you have checked for typo's and the like and everyone else can get it to work but you can't, the common denominator I have ever seen with things NOT working correctly is that particular hosting service. You may find it useful to use a testing environment on your own computer, which allows you to run apache, php and mysql from within your own computer so you can test and build your website offline while still being able to interact with it as if it were online. This will make sure that it is not your host without having to get a new host and spending money to determine that. My preferred testing environment for windows is: Vertrigo if you go to http://www.vertrigo.net it will allow you to download and then install it free of charge. Another one many use is XAMP, there are 3 or 4 different testing environment software out there, all free all automatically integrate Apache, MySQL and PHP and most have same or similar versions of each, the most recent stable versions. If you use a MAC, my understanding is there is one built-in but I don't know anything about that as I don't use Mac. If you do happen to have a second webhost you may want to try uploading your site to that host and seeing if your problems just magically have been fixed.
×
×
  • Create New...