
yamikowebs
Members-
Posts
16 -
Joined
-
Last visited
Never
Everything posted by yamikowebs
-
cant generate 404 headers on pages other than the requested page
yamikowebs replied to yamikowebs's topic in PHP Coding Help
RewriteRule !^(Resources(/.*)?)$ index.php [L,QSA] did the trick -
cant generate 404 headers on pages other than the requested page
yamikowebs replied to yamikowebs's topic in PHP Coding Help
So instead of base.css I get Foo.php again? That doesn't make much sense. Or do you mean you're getting a 200OK with no content? So I started working on a simpler attempt to get the idea down and almost got it with RewriteRule !.(js|ico|txt|gif|jpg|png|css)$ index.php [L,QSA] I want everything to redirect to index.php except for actual files, directories or request for something in the Resoureces directory. That way I can pass image names with the extensions in the url if I wanted and generate proper 404 for requesting images, CSS files etc since they would be stored in the Resources directory. I cant figure out how to get it to only prevent routing on Resources/*. I thought the code below would do it but something is wrong it is redirecting Resources/invalidfile to index.php ReqriteRule !Resources/*$ index.php [L,QSA] -
That example is specifically targeted at classes designed to hold huge amounts of data, where a getter/setter for each mutable property could result in thousands of methods needing to be held in memory. In that case, it's better to have a generic getter/setter for all properties, rather than one for each or none at all, IMO. yes it is slower but its a question of how fast does it need to and if this would be the bottleneck. Most likely it wouldn't be. If speed is important then PHP isn't the best language to be using. Compiled non OOP languages are faster. 1k+ properties is a lot and I would imagine you should be breaking your object down into multiple objects and have an object wrapper or builder pattern. Do you really need 1k+ properties every time you need to do something with the class?
-
generating unique password without going to db?
yamikowebs replied to stijn0713's topic in PHP Coding Help
Multi-threaded software. Multi-core computers. It's very possible to do multiple things at the exact same time with modern computing. My understanding is that even with multithreading things are not truly happening at the same time. Only the processor is multithreaded and things like disk reading/writting and ram access are not. -
Its in situations like your where I think setters and getter are the most useful. with $o->Get($name, $value) I as a new programmer on the team would have no idea what the properties are and what they do. However If I want to get Something with setters and getters I just type &o->Get and all of the things I can set will pop up in my IDE with notes on what they are for, accept, and return. you can do this with public properties but there's a few reasons as to why you want your properties to usually be private or protected. It can cause issues in certain situations which I can not remember of the top of my head.
-
cant generate 404 headers on pages other than the requested page
yamikowebs replied to yamikowebs's topic in PHP Coding Help
It returns 200 ok. In firebug on the html part of the response it has the same output as my main page though =/ This is my first time playing with the ideas of routing with htaccess and MVC so I might have redo the whole thing and start with a more abstract use of it to get the idea down. Would you know of any good tutorials that go through setting 404s for invalid controllers. My URL format is site.com/controller/method/params/moreparams -
Getters/Setters are good practice for a few reasons and depend on your programing environment to make full use of them. 1) It creates an access point which is easier to identify and track when you have multiple objects interact with other objects. It also allows you manipulate information before it goes in or out of the class automagicaly or trigger an event if you have your own event system. 2) If you are using an IDE like netbeans type hinting adds another benefit. You type object->Set and a list of what you can set show up and the same for get. This is more so helpfull when you have multiple people working on a project with a library they are not very familiar with. It is quicker to look at set and get and properties than a huge list of properties although this is arguable. Here's a great link on it with C++ that a friend shared with me awhile back when I asked him the same thing. http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php
-
cant generate 404 headers on pages other than the requested page
yamikowebs replied to yamikowebs's topic in PHP Coding Help
It is sending back the same result as the page request. I.E If I request a non existing page I get a 404. If I request a valid page Foo.php that has invalid links to css files etc. Those invalid files will have the same response as the request for Foo.php -
generating unique password without going to db?
yamikowebs replied to stijn0713's topic in PHP Coding Help
@ChristianF Its not possible for two people to load the page at the exact same time the request are handled in an order. -
cant generate 404 headers on pages other than the requested page
yamikowebs replied to yamikowebs's topic in PHP Coding Help
The above code was tested on my local server. I moved it to my live server on a test domain and got more information. On my live server I was getting an error about output already being sent from another file...This is confusing because the file that is starting the so called output is an abstract class and the line the error is for is an abstract function... namespace Lume\Abstracts; abstract class Chain{ abstract protected static function GetSelf();//this is the line that is starting output abstract protected static function SetSelf(); } -
Since you do not know the exact height you can not do this without a trick like Faux Columns, or tables. You can also play with display properties like display="table-column" Or you can use Javascript with jQuery. $("#div1").height($("#div2").height());//set the height of #div1 to the height of #div2 If needed I can give out a better example code later.
-
generating unique password without going to db?
yamikowebs replied to stijn0713's topic in PHP Coding Help
Use a timestamp or something that uses the timestamp like a hash of the time stamp. I personally would think its better to store who should have access to the survey send an email with just a link. On the page itself check if the user was one of the invited users. -
I have been working on my own framework and learning more advanced PHP than what I was able to learn in college. I use .htacess to redirect all page request to my bootstrap file. The bootstrap file will then parse Request URI and run the necessary controllers etc. If the controller does not exist it runs a 404 controller that send a 404 header. After the controller and vies are made they are passed to a template and then echoed to the page. If I request a faulty page I get the 404 error just fine. However If i request a valid page and the page request css files images that do not exist they will not generate the proper 404 header. They return the same header as the original page requested. Options +FollowSymLinks IndexIgnore */* # Turn on the RewriteEngine RewriteEngine On # Redirect to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php //the tid bit that loads the controller //locate $file = 'Lume/' . self::$AppPath . 'Controller/' . self::$ControllerName; if(!file_exists($file . '.php')){ header('HTTP/1.0 404 Not Found'); $file='Lume/' . self::$AppPath . 'Controller/_404.php'; } //create $controller = str_replace('/', '\\', '/' . $file); if(!is_subclass_of($controller, '\Lume\Abstracts\Controller')) throw new \Exception('Route::Main The controller must extend from Lume\Abstracts\Controller'); self::$Controller =& new $controller(); //run self::$Controller->Main();
-
Again thank you for your reply. I normally did the very same thing to interact with the other mySQLi methods fine. I looked over my old code and discovered in all cases I only used methods that used only 1 parameter. your new solution doesnt do it because the format for bind_param has an unknown number of parameters before hand. a few examples: $stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)"); $stmt->bind_param('sssd', $code, $language, $official, $percent); $stmt = $mysqli->prepare("INSERT INTO Account VALUES (?, ?, ?,)"); $stmt->bind_param('iss', $ID, $email, $name); So I believe this is where I would use call_user_func_array(); This gets the right number of parameters but another rule on the parameters passed is that they need to be passed by reference. I looked into how to do this and here is the final solution: foreach($arg as &$v) $Arg[] = &$v; $return = call_user_func_array(array(self::$Stmt, 'bind_param'), $Arg);
-
Thanks for the reply. Oddly I was able to do this just fine with other methods before. I have since switched to 5.4...Is there a way I can have DB::Bind run the prepared statement when I don't know the number of arguments? If not I can make a getter to get the mysqli stmt. My understanding with prepared statements is they are better because they secure your data automagicaly. I can use the normal query and secure the data automatically like I have been doing. Or perhaps there's other reasons I should switch to using prepared statements? What are your opinions on this?
-
There's a number of questions on this that are answered here but I cant find what is wrong with mine. DB class that uses mysqli which is stored as a property. The prepare, bind and execute are triggered with the magic call methods: public static function __callStatic($name, $arg) { echo '<pre>'; var_dump($arg); echo '</pre>'; if($name == 'Prepare'){ self::$Stmt = self::$mysqli->prepare(implode(', ', $arg)); $return = self::$Stmt; }elseif($name == 'Bind') $return = self::$Stmt->bind_param(implode(', ', $arg)); elseif($name == 'Execute') $return = self::$Stmt->execute(); else $return = self::$mysqli->$name(implode(', ', $arg)); if(!self::GetErr()) return $return; } Also I have a class that generates SQL statements. This is the ouput used in the prepare statement: INSERT INTO account (UName, FName, LName, Email, Password, RecQuestion, RecAnswer, Admin) VALUES (?, ?, ?, ?, ?, ?, ?, ?) Here is the code: DB::Prepare(SQL::Table('account')->Insert([ 'UName' => '?', 'FName' => '?', 'LName' => '?', 'Email' => '?', 'Password' => '?', 'RecQuestion' => '?', 'RecAnswer' => '?', 'Admin' => '?' ])); DB::Bind('sssssssi', $userName, $fName, $lName, $email, $password, $recQ, $recA, $admin); DB::Execute(); As I can see there are 8 types and 8 values to go with it... also here is the output of var_dump($arg) for when DB::Bind is called array(9) { [0]=> string( "sssssssi" [1]=> string(4) "user" [2]=> string(5) "first" [3]=> string(4) "last" [4]=> string(15) "[email protected]" [5]=> string(64) "$2a$10$Tw4eOkUYA6SX8WP8XJfKZeFfOM9htVRJyP0d1iYlka0jNCV/qPGzazakT" [6]=> string(7) "recover" [7]=> string(64) "$2a$10$LrfK2EdkRi6pPdx1tUtPWe8p24T8ISdQHYhW0N06RjbvCrU4Flqiie4jU" [8]=> int(1) }