Jump to content

johnsmith153

Members
  • Posts

    709
  • Joined

  • Last visited

Everything posted by johnsmith153

  1. I've been asked to edit somebody's website for them. There is a file containing about 100 lines of random characters that is loaded by an IonCube loader (or something). This file seems to be the one that contains the problem (if I comment out the bit where the file is included then a whole chunk of the site - including the bit I want to edit - is missing.) Can I edit this file, or is it like this due to encryption or something?
  2. This probably doesn't matter much, but I am using a 'Display' class for final output to the browser. The class will display the obvious HTML header and then display either the full site or the mobile site. It also displays the CSS / JS (which is previously selected in the page-specific controller code as there are variations based on server-side checks). Basically it is the ONLY class that actually needs to send anything to the browser. When I begin output and echo inside the class, that is the end of the script - there is no more server-side code to execute. If I shouldn;t echo inside the class, is it that bad to do so?
  3. johnsmith153

    Site Maps

    I am looking to create a site map to both aid the user and benefit SEO. (1) I will have something very similar to www.apple.com/sitemap (with a link to it in the footer of every web page). I'm just planning on doing a html page, nothing special. Is this a good way to do it? Does it matter? (2) Imagine a social network. If I did the Site Map like mentioned in point 1 above, would there be a benefit in adding some random links which would be to a randomly chosen list of forum profiles: So: Sitemap. site.com/about site.com/contact (etc.) and... site.com/robert-smith site.com/dave-brown (these links are generated server-side randomly) Is there a benefit to randomly add links like above - as this is to someone's profile I can't see how search engines would ever index profile pages. Imagine Facebook, how would use profile pages ever be indexed on that site? (3) As well as the site map for website visitors I will generate an XML one to submit directly to all the search engines. Is this a good idea? (4) A robots.txt file to tell robots where the sitemap.xml is. Am I on the right track? Have I missed anything?
  4. Great. Thanks for help from all.
  5. I am putting together a basic OOP application. There is one access page - index.php. This is the kind of thing my index.php page does: <?php //get address bar / POST / GET info $request = new Request(); //if POST request submitted then the code is executed here before redirecting back to the page (stores POST vars in SESSION) if($_POST) { $post = new Post(); } //checks device using (mobile etc.) and decides if any action needed (really old mobiles are sent straight to a mobile site) + stores details of the device using $device = new Device(); //main controller to decide files to load for header, page-controller and view $mainController = new MainController();//__construct gets the files //check login / autologin $login = new Login();//checks if should log in automatically (page controller below will throw off when MUST be logged in as not always) //execute the page controller $mainController->pageController(); //header $mainController>header(); //view $mainController->view(); ?> Is ts the way to go about it? Is listing class executions down the page like this the right way or should say the main controller execute a lot of these? Please don't post your index.php page, I am looking how I can adjust mine - unless mine is utter rubbish of course! I don't want to learn one of the ready-made frameworks just yet - but will do soon. Thaks in advance.
  6. Is using class autoload slower than including them yourself? Should I include/require the class file and use class autoload as a backup in case I had forgotten, or can I just let class autoload load all the class files and never worry about including/requiring. All classes are in the same directory and are always picked up - just want to know if it takes more time. Is it much of a difference? Are we talking 1 or 2 milliseconds per request???
  7. I am thinking of creating a class that will be instantiated first in all scripts and will gather all details of the url entered and store as properties of the class. I use mod_rewrite so the url needs to be split up and stored in various ways. This class would deal with all POST and GET variables and be pretty important and used a lot. If a link needs generating (so to convert the current one into the mobile site one) or some other server-side generation then this class would also provide the results for that. If a server-side redirection was needed then this class would do that. (1) Does this sound like good OOP design as I'm not sure? (2) The problem is that this class would be used so many times by nearly all other classes that I don't know how to make the instance available to these other classes. It could be used by every class. Global?? Passing in to EVERY other instantiated class?? Neither seem a great idea.
  8. Imagine a site programmed using full OOP. Where would you store information like this: $companyName = "ABC Ltd"; $companyPhone = "02476 999 999"; $companyAddress etc... Would you just define them in the public scope? (and use global or pass them in when needed??) Is there a better way? They will be needed in more places than just a navigation bar and would be needed by more than one class.
  9. Thanks for the reply thorpe. The last time you said this I had forgotten the problem with my web host requiring a different user to be setup for each database. This question is the first time I mention this. Do I? (a) Connect to db1, perform various queries, CLOSE, then connect to db2 and perfrom queries. OR (b) Connect to db1, perform various queries. Then connect to db2 without closing db1 and perfrom queries on db2. I suppose the key thing is: does it take time to close a connection? I doubt it's a major difference, but helps to do it the right way.
  10. It would be a case of mainly using database 1 which holds 70 or so different tables. Occasionally database 2 will be used (holding lots of financial account information / transactions for lots of customers). Usually I'd do all db1 queries then all db2 - as swopping back and forth would be pretty crazy I suppose. I just need to know if it is better to open a new connection or close the existing. Can't be a big difference but does it take time to close one? I'm also aware of the limit of 500 connections per user, which isn't an issue at the moment but could be one day. I use a couple of stored session values to query the tables in db2, so a JOIN query is not required. It's pretty rare that db2/3 are used. There would be occasions where db3 is used, and sometimes (rarely) all three together.
  11. On some occasions I need to connect to a second and third database in the same script (maybe 5% of scripts have at least a second connection). Usually I would just select the new database. However, my host requires different users to be created for each database. What is the best way to do this? Close current connection (say db1) and open new (say db2) OR keep all open, creating 2nd and 3rd connections. I am happy with the design of my database, and don't want to merge all these tables into one db. Overall I am still happy with my host, so I'd rather not change.
  12. No, you're being silly. All you've done is used type hinting and added some empty functions in a parent class so as to ensure the method exists. A bit like completing a jigsaw with one piece missing. I'd tell someone to add the missing piece, you'd imply that the whole jigsaw is rubbish and that they should start again. That said, thanks for all your help.
  13. Would it not have been better to say something like this? "Yes, your example does everything you asked for, however, it doesn't do xyz which is very important in circumstances such as abc. If you are developing only for yourself or are maintaing a small site then you can probably get away without some of the advanced things for now, but I really suggest looking into this very soon."
  14. So what is wrong with mine? You made it sound as though mine was wrong. All I wanted to know is how to call another class and avoid using so many static calls. Your example is slightly better (and slightly more advanced than mine), but there's no need to make me think anything was wrong with mine fitting what I wanted it to do. Thanks again for all your help.
  15. Isn't this exactly what my last example did?
  16. I'm not talking about a database. What design? They're examples. The question is overall in OOP. If I find mysef using a static call (because I don't have the instance available) should I pass the instance in? So, how would I make the instance (of another class, say class B) available in the class I am working with (say class A)?
  17. thorpe, thanks for your help (and others who have posted). Also (forget the Database class for a second), if I find myself doing this (which you have mentioned isn't good): <?php class Two { //lots of other stuff as well of course public function whatever() { One::something(); } } $two = new Two(); ?> Should I really be doing this: <?php class Two { private $instanceOfOne; //lots of other stuff as well of course public function __construct($one) { $this->instanceOfOne = $one; } public function whatever() { $this->instanceOfOne->something(); } } $one = new One(); $two = new Two($one); ?> If not, how else do I prevent having to use static calls (One::something).
  18. No, the db design isn't flawed. There are 3 databases - all are on the same server. I'm sure there are areas for improvement, but I'm happy to leave this as it is. The key thing for me is the number of connections I'm creating. Should I just be making one connection and selecting a different database rather than making as many connections during the script as number of databases I am dealing with? Is this where I am going wrong? (when I say 3 databases, I mean 3 x MySQL databases holding lots of tables (all controlled on PHPMyAdmin), I'm not talking about different database types)
  19. I definitely have the need for more than one database. This can't be changed. People / products are examples. Are you saying to use the connection to select db1, perform the query and then select db2 (same connection) and perform that query? I'm sure there is a reason why I don't, but can't think of one now! thorpe said "Multiple databases are a rarity", did he mean using more than one connection is a rarity?
  20. So should I be using requinix's example? How would I fit that into what I already have? I currently do DB access like this: class DatabaseAccess extends mysqli { public function __construct($dbName) { parent::__construct("etc. etc. etc."); } public function escape($val) { return parent::real_escape_string($val); } //and various others of course } $db1 = new DatabaseAccess("people"); $db2 = new DatabaseAccess("products"); I am trying to get rid of the need to instantiate $db1, $db2 etc.
  21. Would something like this be the right way to do it? <?php class DatabaseAccess extends mysqli { public function __construct($dbName) { parent::__construct("etc. etc. etc."); } public function escape($val) { return parent::real_escape_string($val); } //and various others of course } class DatabaseControl { private $instances = array(); public function __construct() {} public function instantiate($databaseName) { $this->instances[$databaseName] = new DatabaseAccess($databaseName); } public function closeAll() { //close all instances of Database foreach($this->instances as $db) { $instances[$db]->close; } } } $db = new DatabaseControl();//do this once only per script //create new connections to each of different databases $db->instantiate("people"); $db->instantiate("products"); //close ALL instances that have been created $db->closeAll(); ?>
  22. Same with: http://php.net/manual/en/function.stristr.php Use it to emulate the before_needle php V5.3 : <?php //$h = haystack, $n = needle if($pos=stripos($h,$n)) $string=substr($h,0,$pos); ?>
  23. The most recent comments on php.net are advising how to emulate for pre 5.3. http://php.net/manual/en/function.strstr.php
  24. Is it ok to do this? class Two { function anything() { classOne::anyMethod(); } } I'm sure it is but this doesn't pose very well for if I wanted to swop out one class for another. I'd then have to make changes to the code (unless I were sure all classes were named the same). -- What I want it for (and this may be another issue), is this: I may need to create more than one database instance: //Database exends mysqli $db[1] = new Database(2);//database 2 used this time $db[2] = new Database(5);//db5 I then always use Database::closeAll() at any point in my script to ensure all connections are closed. Of course $this->close wouldn't close all instances/connections, just the one I was working on. I know I don;t have to close all connections, but I may as well, and there are other occasions where the first part of this question applies, so please don't just respond "no need to close". Database::closeAll() is this: public static function closeAll() { //closes ALL active instances (not just this one) global $db; foreach($db as $v) { $db[$v]->close(); unset($db[$v]); } }
  25. Ensure you use this //this uses current value in $_GET['value'] (don't provide a new one) getValue(""); ...and use is_null instead of ==NULL
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.