PHP - How To Structure Website With Accompanied Microsites
I have a script called getstarted who's purpose is to create microsights which are located as:
/var/www/html/microsite1/index.php /var/www/html/microsite1/lib/ (symbolic link) /var/www/html/microsite1/administrator/index.php /var/www/html/microsite2/index.php /var/www/html/microsite2/lib/ (symbolic link) /var/www/html/microsite2/administrator/index.php /var/www/html/microsite3/index.php /var/www/html/microsite3/lib/ (symbolic link) /var/www/html/microsite3/administrator/index.phpEach of the index.php files looks like: define( '_VSEXEC', 1 ); // Set flag to indicate that this is a parent $file=__FILE__; $type='back'; //or front require('/path/to/mainfile.php');Question: Should the microsites be virtual servers or just subfolders? If there are many, seems like virtual servers are not a good solution, right? Instead of accessing a microsite as http://mydomain.com/...site1/index.php and http://mydomain.com/...ator/index.php, I would like to do so as http://microsite1.my...n.com/index.php and http://microsite1.my...tor/index.php. How is this best accomplished? The key to the microsites being unique is the name of the folder (microsite1, 2, 3, etc). Note that the user may later change the sites name (i.e. microsite1 to bobs_site) as well as the administrator link (i.e. administrator to bobs_backend) using the administrator PHP application. My mainfile.php which is included in each of the index.php files simply gets the name by using basename(dirname($file)), and then queries the DB using this name to get the microsite specifics. Is there anything inherently wrong with this approach? A separate session cookie is used for the front microsite (http://mydomain.com/...site1/index.php) and the accompanying administrator microsite (http://mydomain.com/microsite1/administrator/index.php). The same session cookie should be used whether accessed as http://mydomain.com/...site1/index.php or http://microsite1.my....com/index.php, and the same for the two admin entry points (note that www.mydomain.com is rewritten to mydomain.com). I originally started asking this question in post http://forums.phpfre...ins-and-paths/, but don't think I was clear with my requirements. Currently, I have the session cookies for both the front and admin site as domain ".mydomain.com" and path "/microsite1/" The accompanying session is something like array('front'=>array('bla','bla'),'admin'=>array('bla','bla')). In hindsight, I think this was a poor decision as front users and admin users can logoff which should delete their session, and this causes both the front and admin session to be deleted if they are concurrently logged as as both. Recommendations how best to implement this (no detailed code required, just provide general approach). Thank you REFERENCE ONLY. My website has five pages which are implemented using files home.html, features.html, pricing.html, and main.php located in my HTML root directory (/var/www/html). home.html, features.html and pricing.html are accessed directly. main.php is accessed as http://mydomain.com/...ted&c=foo&d=bar for getstarted and similarily for contactus. Instead of using this as the URL, I would like to use http://mydomain.com/getstarted, http://mydomain.com/getstarted/foo, or http://mydomain.com/...arted/foo/bar. I have successfully implemented this by adding the the following to my Apache configuration file /etc/httpd/conf/httpd.conf as shown below (no need to check it out unless you want to). I wish to keep this functionality intact. <VirtualHost *:80> ServerName mydomain.com ServerAlias www.mydomain.com mail.mydomain.com smtp.mydomain.com ftp.mydomain.com DocumentRoot /var/www/html <IfModule mod_rewrite.c> RewriteLog /var/log/httpd/rewrite.log RewriteLogLevel 3 </IfModule> <Directory "/var/www/html"> Allow from all Options +Indexes <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / ## If the request is for a valid directory, file, or link, don't do anything RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -l RewriteRule ^ - [L] #remove the trailing slash RewriteRule (.+)/$ $1 # If you add this first rule to support views, be sure to remove the QSA flag from the second rule (maybe not required since the first rule has the L flag) # replace my-page/my-controller/data with main.php?p=my-page&c=my-controller&data=data RewriteRule ^(getstarted|contactus)/([^/]+)/([^/]+)/?$ main.php?p=$1&c=$2&d=$3 [L,QSA] # replace my-page/my-controller with main.php?p=my-page&c=my-controller RewriteRule ^(getstarted|contactus)/([^/]+)/?$ main.php?p=$1&c=$2 [L,QSA] # replace my-page with main.php?p=my-page RewriteRule ^(getstarted|contactus)/?$ main.php?p=$1 [L,QSA] #Replaces file if "." is not in the string (i.e. it will not replace file.html, but will replace file RewriteRule ^([^.]+)$ $1.html [L] </IfModule> </Directory> </VirtualHost> Similar TutorialsHiya, What's the best and most secure way of structuring a website? I have looked at various forum packages (.e.g phpBB, myBB, and smf), and they each seem to use a switch statement in the index.php file. When you go to a section of the website, a "GET" variable is passed, and the relevant area of the website is loaded through the switch statement. Is this the best and only way? I would appreciate any body's thoughts on this topic. Thanks, FishSword Hi all, So I've nearly finished coding my first website. Currently all the files are in the same directory on my harddrive, but I now want to create a proper folder structure that will be secure. I have been reading up on this a lot on various websites, but it seems like most articles on this topic are targetted at developers with much more complicated websites than mine, and it's all a bit over my head. My website is quite simple, it consists of the following: 1) html files and php files that print something to the screen that I want to be accessible to the user by typing in the url in the browser. 2) html and php files that are called upon by 1, they either print something to the screen inside an iframe or not at all - I want these files to be accessible only to 1) and not directly to the user by typing the url 3) image files and includes, etc. (and also 4) a MySQL database, but maybe this doesn't really have anything to do with the website folder structure.) What should my directory structure be and where should I put 1), 2), 3), etc.? Thanks a lot! When having different levels of directories, using relative paths will not work anymore, for example: controller - authentication File 1: include('../../model/header.php') model File 2: header.php view File 3. style.css The header.php file includes the css file with a relative path, but the problem is it includes it as follows: ../view/style.css When now the header.php file gets included into File 1 in the folder "authentication", then the css file will not be accessible anymore, for it to be accessible you would have to go two directories up. In this sense my question is, what would be the proper path structure for a folder structure with multiple levels? Should I rather use absolute paths, I am not so prone of absolute path. What if the folders changes a bit, or the domain changes, or the location changes? I have multiple forms within one php file. What is the best structure to use? Code: [Select] if (isset($_POST["one"])) { include... } if (isset($_POST["two"])) { include... } if (isset($_POST["three"])) { include... } OR Code: [Select] if (isset($_POST["one"])) { include... } else if (isset($_POST["two"])) { include... } else if (isset($_POST["three"])) { include... } thanks Hi. I am creating a database where a user can store up to 50 names of their family members. I have two table structures in mind and curious which one is the more efficient structure. ==================================================================================================== TABLE A: userid-firstfamilymemberid-firstfamilymembername-secondfamilymemberid-secondfamilymembername Note:(the columns would repeated until the fiftiethfamilymemberid and fiftiethfamilymembername for a total of 101 columns) TABLE B: userid-familymemberid-familymembername ====================================================================================================== which is more efficient... Table A which would have more columns but less rows or Table B which would have less rows but more columns.. also keep in mind that the fixed amount is 50 family members per a user. Thanks in advance. Hello everyone I want to know why are these functions discouraged because I have a problem ***************** http://mx.php.net/manual/en/function.spliti.php Warning This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. ***************** I have a long list of standard features of some products (90 features 1800 products) which I am integrating in a CMS. I have to elaborate a CREATE, READ and MODIFY section for the products and I was thinking of using check boxes and if statements with 90 columns in my DB for each feature. (I hope there is an easier way to do this) Before I typed in all the features in one column and splited it with the previous functions mentioned, but it doesn't work for the modify section of the CMS. I am trying to learn a method in which I can easily integrate this 90 standard features in the CMS. Does anyone has a good idea? Hy I have a question. Do you think that the code structure from php affect the SEO? I mean if the application is made in basic php or OOP. thk Hello dear friends, Let say we have Code: [Select] $to = "gigi"; then we have link like this Code: [Select] mysite.com/file.php?id=$1 We can change it to new form by add rule at .htaccess codes Code: [Select] RewriteRule -(.*)\.htm file.php?id=$1 So that the link be like this Code: [Select] mysite.com/$to-$id.htm it will works , Now what if i want to make the link like this Code: [Select] mysite.com/$id/$to.htm what will be the .htaccess code in this way ??? thanks I'm currently working on a site that has about 4 separate panels on the page that all use an include to populate. Each include is interacting with the database and I'm thinking that it might congest the databse to have each panel connecting to the same data base and getting data when the page loads. I was wondering if it would be good practice to take all the connections and functions and put them on a 5th include at the top of the page. This way the connections and functions would be available to each include. Is this a good idea? Will it be a problem for the 4 includes to ask the php function list include for data? Is it better to just let each include contain only the code it needs? Also, say I have 20 functions on the php include and one site page only needs to use 1 function. Would the php function include still loop thru and connect to the database for all 20 functions just because it is included or will it only use the bandwidth needed to execute the 1 function it is being asked to use? Hope that's not over confusing. Thanks! Alright guys.. I need some advice, some recommendations and definitely some help. I've got a submission form for users to upload an image and some basic personal information. The client wanted the information to be divided by the North America (specifically N.A. and not U.S.) and Europe.. so I created a database table with the typical structu a row for the user's name, email, etc. I also added a row labeled "regionid" in which "1" would equal North America and "2" would equal Europe. This "regionid" row would obviously organize the submission by their country. The client specifically wanted to label North America but mentioned only users from the States would probably only submit images, etc. Users could choose if they were submitting a form for US or Europe and "regionid" would be filled by which form was chosen. Recently, the client threw a curveball and now wants Canada as part of the North America submission form. Now, I don't want to add Canada as another option for my "regionid" row because it does belong under North America. However, I need to alter the structure of the database I currently have so that it can now organize if under North America or Europe, and if under North America, if the submission falls under the United States or Canada. I was thinking of adding a drop down menu under the North America form with the options US or Canada. Do you guys have any advice or other directions you would take to solve this problem.. that is, if my situation is even understandable? I found it pretty difficult to explain! Apologies! Hi all, I am working on php project and willing to use the "everything as a plugin" idea so alot of people can easily contribute. I am wondering how I can make a php page that includes my plugins, without having to hardcode them(as in require_once, ...). And afterwards it should be possible to execute a function on each of the enabled plugins. Especially the "hardcode" part I am not sure on how to fix it. As for executing a function for each plugin (so that will be a Class object), I wonder how I can make an object of each class from an interface and then execute a function without hardcoding the creation of all objects. Any one ideas or experience with something like this? Thanks in advance. Hey guys ;-) I got a client that asked me today to create him an MLM type website. The first part of my work would be to test if there system works so I need to run a full demo of the multilevel structure. The MLM structure works as follow: 1 person finds 2 members and they then find 2 more each and so on until we reach 100 level deep. If i got this right, At level 5 there will be 25 members At level 10 there will be 100 members At level 20 there will be 400 members At level 40 there will be 1.600 members At level 100 there will be 10.000 members So at the end of the demo there should be 10k members inserted into the table The table looks like this: id, parent, level, under Parent is the ID of the guy that recruited him, level is the level that guy is at (level 1, 2 , 3, 4 or 5) and under is the number of people under him. I need to run a script that will insert all the data into that table so that we can run some test on the liability of the project so we can set the rates right. At first I thought it would be a piece of cake ... but when I started I found out very fast that populating the MLM network 5 level deep is gona be tricky ... my first attempt gave me a result that looks like this: Code: [Select] |0| |1|2| |x|x|3|4| x|x|x|x|x|x|5|6| As you can see the script only grab the last id then adds 2 new members then uses the last one as the parent and starts over ... So my script is useless and I did not figer out how to do everything in 1 step ... Any help would be appreciated. Hi all,
I would like some input on database structure for a website that will sell car parts. Necessary fields a
Manufacturer
Part type (eg: exhaust, brakes, engine etc)
Part number
Description
Year & make of vehicle it fits (may need to be separate fields, I don't know, this is my main conundrum) **
Keep in mind, this is a basic example and purely hypothetical at this moment. I haven't done any coding yet.
My main roadblock at the moment is figuring out how to engineer part compatibility in conjunction with a search. Many parts fit many different vehicles. For example, part A123 could fit:
1999-2004 Jetta 2.0
1999-2004 Golf 2.0
1999-2004 Passat 1.9
In your opinion, what would be the most efficient way to store and retreive matching parts? Would I have each model as a separate row? i.e:
row 1: 2002-2004 Jetta ... part A123
row 2: 1999-2004 Golf... part A123
row 3: 1999-2004 Passat... part A123
Basically I would have many duplicate rows where only the year and vehicle model changes. This would definitely work, but would eventually lead to a very large and messy database.
There are already companies that offer a service such as this, but I am looking at looking to sell less products and secondly, in a different language. At the moment, I'm trying to figure out the best way that I could do it. Once I have an idea in mind, then I can decide whether I want to go ahead with that or use a pre-made commercial platform.
Dear people here at phpfreaks
I am working on updating an old guestbook with outdated code (predecated). I will follow the suggestions I have received here on this forum already by using the new MySQL PDO technique. I am pretty rusty on PHP and MySQL, since I haven't been using it for years. So it took me a while to get Xampp running and installing Virtual hosts, so I can test my code locally. This is all working now. I have decided to start from scratch, building my guestbook up gradually in order to be able to understand each step better. I am inspired by the following tutorial:
http://wiki.hashphp....ySQL_Developers
So far I have created four files
1. contribution_to_guestbook.html
2. put_in_guestbook.php
3. show_content_of_guestbook.php
4. mysql_functions.php
The guestbook is implemented as a table with the name guestbook in the MySQL database with the name my_database. The database contains six fields, which a id, time, ip, name, email and contribution. The user can write a contribution by filling in his name, email address and contribution in the form placed in the first file. These data for the fields name, email and contribution respectively are being sent to the second file. At the same time the datetime is automatically registered along with the IP address of the users computer in the fields time and ip. When inserted in the table in the database via the second file, the primary field id is automatically added and incremented by 1. After the insertion in the database, the user is directed to file 3, where the content of the whole guestbook is being displayed for the user to see. The 4th file is containing the connection details for the database, including the password.
NB! The IP address of the users computer is not being displayed but only collected in the case one want to block spammers from specific computers with fixed IP addresses. In order to better block for spam from computer bots, I will later place a question in the first file to only admit humans ...
My questions
Is the structure of my guestbook convenient? Would it be appropriate to create functions to make the code more readable and if so, how can I do it? I wanted to make a prepared statement in the 3. file in which I select the content on the guestbook in order to display it. Can it be done, and if so how do the code look like? I know I need more error handling. Also I need to test user input. For example if no contribution is being written, an error message should be shown to the user, etc. Do you have some suggestions here and how to do it? What about security? I hope the password for my database will not be accessible in any way? I will appreciate any comments on the four questions above and eventual something else I have overlooked! I hope my thread is not too long. Hope for some replies ... Here is my code so far (still just a framework!): 1. contribution_to_guestbook.html <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contribution to Guestbook</title> <style type="text/css"> body,td,th {font-family: Verdana, Geneva, sans-serif;} form1 table tr td {color: #06C;} h1 {color: #0000A0;} </style> </head> <body> <form method="POST" action="put_in_guestbook.php"> <h1>Contribution to Guestbook</h1> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td>Name</td> <td> <INPUT type="text" name="name" size=40 maxlength=100> </td> </tr> <tr> <td>Email</td> <td> <INPUT type="text" name="email" size=40 maxlength=100> </td> </tr> <tr> <td valign="top">Contribution</td> <td> <TEXTAREA name="contribution" cols=60 rows=10></TEXTAREA> </td> </tr> <tr> <td></td> <td align="center"> <INPUT type="submit" value="Submit contribution"> </td> </tr> </table> </form> <p></p> </body> </html>2. put_in_guestbook.php <?php require("mysql_functions.php"); $ip = $_SERVER['REMOTE_ADDR']; //Clients IP address collected $name = $_POST['name']; //Data from input form etc. $email = $_POST['email']; $contribution = $_POST['contribution']; try { $db = new PDO('mysql:host='.$server.';dbname='.$database.';charset=utf8mb4', $username, $password); //Connecting to database $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $stmt = $db->prepare("INSERT INTO guestbook(`time`, `ip`, `name`, `email`, `contribution`) VALUES(NOW(), ?, ?, ?, ?)"); $stmt->execute(array($ip, $name, $email, $contribution)); //Placing the new contribution with details in Guestbook $db = NULL; //Closing database header("Location: show_content_of_guestbook.php"); //Redirecting to another page to show content of guestbook } catch(PDOException $ex) { echo "Could not insert into guestbook"; } ?>3. show_content_of_guestbook.php <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf8mb4" /> <title>Guestbook</title> </head> <body> <?php require("mysql_functions.php"); header('Content-Type: text/html; charset=utf-8'); try { $db = new PDO('mysql:host='.$server.';dbname='.$database.';charset=utf8mb4', $username, $password); //Connecting to database $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); foreach ($db->query('SELECT * FROM guestbook') as $row) { echo "Contribution number: ".$row['id']."<br/>"; echo "Time: ".$row['time']."<br/>"; echo "Name: ".$row['name']."<br/>"; echo "Email: ".$row['email']."<br/>"; echo "Contribution: ".$row['contribution']."<br/>"."<br/>"; $db=NULL; //Closing database } } catch(PDOException $ex) { echo "An error ocurred"; } ?> </body> </html>4. mysql_functions.php <?php $server = 'localhost'; $username = 'root'; $password = 'my_password'; $database = 'my_database'; ?>Regards, Erik Edited by erikla, 16 July 2014 - 07:52 AM. I'm starting on a project of building a simple forum for my website. My question is, what would be the best table structure for the database? I've seen a couple different methods. The simplest is a table for categories, forums, threads, and replies. The only problem with that is that it makes it difficult to gather the thread update info for the forum list on the index. You know, like "Latest thread posted by {USER_NAME} in {THREAD_NAME} at {THREAD_TIME}", that whole deal. The second theory, which is what I'm thinking of using, is having tables for categories, forums, and messages(which would have a column for both messageid and threadid). the only problem with that is that i'm not sure of how to distinguish the difference between a regular reply and a new thread. Any ideas? I typically structure my applications something like the following. I lump general functionality into a given component. For instance, I might have com_users component which deals with user administration, and implements the ability to view a list of users, view a given user, delete a user, edit a user, etc. This structure was borrowed long ago from my learning PHP Joomla days which I no longer use. index.php figures out which component is being accessed, evokes the controller which gets data from the model and sends the data to the view. The view defined in each component only deals with the central content, and mainTemplate.php deals with the peripheral. First question. Is there anything inherently wrong with this approach? Second question. I am looking to start using Twig. Would this same structure work? I would replace /var/www/html/lib/templates/mainTemplate.php with a Twig file, and replace var/www/components/component1/views/view-1-1.php, etc with Twig files which extends the main Twig template. /var/www/components/component1/controllers/controller-1-1.php /var/www/components/component1/controllers/controller-1-2.php /var/www/components/component1/models/model-1-1.php /var/www/components/component1/views/view-1-1.php /var/www/components/component2/etc/etc /var/www/html/lib/templates/mainTemplate.php /var/www/html/lib/templates/mainCSS.css /var/www/html/lib/js/someJSforAllComponents.js /var/www/html/lib/components/component1/js/someJSForComponent1.js /var/www/html/index.php Hi guys, I am starting out on mvc, I been reading up on it for a bit now.. and I was just wondering if anyone can take a quick look at it and give me some insight on it? maybe some suggestions etc.. I will be using this for a some what medium site when I know that it is good enough to be published. Note that its not done.. in reality I just need to make sure I am heading in the right direction. Hey guys, I have a bunch of categories and products in a tree format. For several reasons I need to restructure them from the tree format into a flattened format. I have 2 arrays, one full of categories, the other products. Each category and product has an ID, and a reference to it's parent's ID. The top level categories reference to 0. What I need is to have the categories output like thus: Top Level Categories: Category 1 Category 2 Category 1 Sub category 1 Sub category 2 Category 2 Sub category 3 Sub category 4 Sub category 1 Product 1 Product 2 Sub category 2 Product 3 Product 4 Sub category 3 Product 5 Product 6 Sub category 4 Product 7 Product 8 There could be an unlimited number of sub categories within categories before we get to products, so this needs to be done through a function, however I cannot for the life of me think how to do this. Initially I thought about using 2 arrays, a buffer of categories outputted, and a queue of categories to be outputted, but quickly realised that when I go more than 2 layers deep I can't keep track of the queue's properly.
Hello,
I have a table like this: CREATE TABLE days ( id INT AUTO_INCREMENT, daya INT, dayb INT, PRIMARY KEY (id) ); INSERT INTO days VALUES (70, 19, 18), (69, 20, 17), (68, 24, 25), (67, 19, 18), (66, 19, 17), (65, 17, 16);
$sql = "SELECT d1.id AS id1, d2.id AS id2, IF((d1.daya-d2.daya)=1,1,0) + IF((d1.daya-d2.dayb)=1,1,0) + IF((d1.dayb-d2.daya)=1,1,0) + IF((d1.dayb-d2.dayb)=1,1,0) AS tcount FROM days AS d1 , days AS d2 WHERE d1.id IS NOT NULL AND d2.id IS NOT NULL AND d1.id > d2.id"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["id1"] . "</td><td>". $row["id2"] . "</td><td>" . $row["tcount"]. "</td></tr>"; } echo "</table>";
Id1 Id2 Count 50 49 1 50 48 0 49 48 0 50 47 1 49 47 1 48 47 0 50 46 1 49 46 1 48 46 0 47 46 1 50 45 1 49 45 1 48 45 0 47 45 1 46 45 1 I need to convert the table into this form: id1 goes down the first column, and id2 is in the first row. How can i do this, please? can you give me some help? thank you! id2 49 48 47 46 45 id1 50 1 0 1 1 1 49 0 1 1 1 48 0 0 0 47 1 1 46 1 45
Hi all. I'm starting a mini-project with the purpose of creating PHP generated charts. I just had a quick question on the class structure that I should use. My instinct tells me to do it like this: class chart{ function pie(){ } function bar(){ } } Is that a legitimate structure or is there a better way to do this? |