-
Posts
969 -
Joined
-
Last visited
Posts posted by Destramic
-
-
hey guys i have a little problem and not sure of the best way to tackle it, if you could help please.
i have 2 url which could be like so
tasks/ricky-powell/week/14/08/2018 tasls/ricky-powell/day/14/08/2018
now if /day/14/08/2018 then thats a simple query.
SELECT task FROM tasks WHERE scheduled_date = '2018-08-14'
but...if users selects to view tasks by week (mon-fri) then it becomes a little bit complicated.
14/08/2018 is today which is a tuesday, and i would need to get the range from date mon - fri.
would it be easier to:
1. ensure weekly url is a monday?
2.work out the date (mon - fri) view mysql/php
3. something else.
thank you.
-
I feel with annotation also your force to learn a new syntax...I could also use traits for certian fields that are use widley throughout my site, which is cool.
I concur with what your saying, and I'd also be able to get rid of the abstract too. I'll implement what you've said and try to build upon that.
Thank you for your great input once again.
-
last year a made a validion script that works simular to this but using annotation (like symphony). it was very long winded and messy, but although it worked perfectly i was never happy with how complicated it was.
well i had a brain wave last night on how to simplify a validator without any annotation bs!
this took me minutes to write, and would be nice to have an overall critique from you guru's.
validator:
<?php class Validator { private $entities = array(); private $error_messages = array(); public function __construct(array $entities) { foreach($entities as $entity) { $this->check_entity($entity); } $this->entities = $entities; } private function check_entity($entity) { if (!is_object($entity)) { throw new Exception('Validator: Entity must be an object.'); } else if (!is_subclass_of($entity, 'Entity')) { throw new Exception('Validator: Parent entity has not been implimented.'); } return true; } public function validate(array $data) { foreach ($this->entities as $entity) { foreach ($data as $property => $value) { if (property_exists($entity, $property)) { $entity->{$property} = $value; } if (method_exists($entity, $property)) { call_user_func_array(array($entity, $property), array('value' => $value)); } } $this->error_messages = array_merge($this->error_messages, $entity->get_error_messages()); } } public function get_error_messages() { return $this->error_messages; } public function is_valid() { return empty($this->error_messages); } }
login entity
<?php include_once 'entity.class.php'; class Login extends Entity { public $username; public $password; public function username() { if (empty($this->username)) { $this->add_error_message('Username: username is empty'); } } public function password() { if (empty($this->password)) { $this->add_error_message('Password: password is empty'); } } }
abstract entity
<?php abstract class Entity { private $error_messages = array(); public function add_error_message(string $message) { $this->error_messages[] = $message; } public function get_error_messages() { return $this->error_messages; } }
test it all out!
<?php include_once 'validator.class.php'; include_once 'entity/login.class.php'; $validator = new Validator(array(new Login)); $post = array( 'username' => 'john.doe', 'password' => null ); $validator->validate($post); if (!$validator->is_valid()) { print_r($validator->get_error_messages()); }
result:
Array ( [0] => Password: password is empty )
the script will work with multiple entities too.
thank you guys!
-
requinix thank you for your time in breaking down how things should work, as it's all alot clearer to me now and i'll be sure to adopt these changes into my framework.
thanks again.
-
brilliant i understand how it should work now....i'll change my code around so the request and response get sent from front controller to my controller.
that way i'll be able to run this code in my front controller if dispatched.
$controller = $this->dispatcher->dispatch(); $response = $controller->get_repsonse(); if ($reponse->get_response_code !== 200) { // deal with respsone code! { else { $response->send(): }
also should i send my view through my front controller to controller like request and response?...or initialize my view in my asbtract controller?
thank you for your help!
-
hey guys im trying to build custom http error pages into my framework but after days of thinking, i must admit defeat and ask for some help.
ok so if i try to access a route which doesnt exist my dispatcher will send a 404 error in the send_404_error() method were http_reponse_code(404) is set and then it'll dispatch to the error controller (no problem).
dispatcher:
<?php namespace MVC\Dispatcher; use HTTP\Request; use HTTP\Response; use Exception; class Dispatcher { private $request; private $config; private $class; private $controller; private $method; private $dispatchable = null; public function __construct(Request $request, $config) { $this->request = $request; $this->config = $config; } public function dispatch(array $parameters) { if ($this->dispatchable) { $this->request->set_controller($this->controller); $this->request->set_parameters($parameters); $controller = new $this->class($this->request); $this->reset(); return call_user_func_array(array($controller, $this->method), $parameters); } else if ($this->dispatchable == false) { return $this->send_404_error(); } return false; } public function is_dispatchable(string $controller) { $this->format_controller($controller); if (!class_exists($this->class) || !method_exists($this->class, $this->method)) { return false; } return $this->dispatchable = true; } private function format_controller(string $controller) { if (substr_count($controller, ':') != 2) { throw new Exception('Dispatcher: Invalid controller format.'); } $this->controller = $controller; list ($module, $controller, $method) = explode(':', $controller); $this->class = $module . '\Controller\\' . $controller; $this->method = $method; } public function send_404_error() { if (isset($this->config->framework['http_error_controller'])) { $error_controller = $this->config->framework['http_error_controller']; if ($this->is_dispatchable($error_controller)) { (new Response)->set_response_code('404'); return $this->dispatch(array( 'status_code' => 404 )); } else { throw new Exception('Dispatcher: HTTP Error undispatchable.'); } } return false; } public function reset() { $this->class = null; $this->controller = null; $this->methid = null; $this->dispatchable = false; } }
question what happens if i want to send a http 404 error in any of my controllers?
<?php namespace Custom\Controller; class Test extends Controller { public function test($status_code) { // user not authed! (new Response)->set_response_code(404)->send(); } }
when the 404 response is sent, i could check in send() method that the http_repsone_code() is 200, if not then dispatch to the error controller.
if ($this->get_response_code() !== 200) { return (new Front_Controller($config))->run('custom:error:http_error', 404); } return $this->content
all that being said there is still a http_repsone_code(404) after that snippit is run and the response will keep looping because the repsone code isn't 200.
response:
<?php namespace HTTP; use HTTP\Response\Header; class Response { private $content; public function __construct($content = null) { $this->set_content($content); } public function set_content(string $content = null) { $this->content = $content; } public function set_response_code(int $status_code) { http_response_code($status_code); } public function get_response_code() { return http_response_code(); } public function headers() { return new Header; } public function send() { echo $this->content; } }
can someone please talk some sence into my on how i should handle http reponse codes in my framework.
thank you.
-
it was just me trying all options to add transparency to that div.
but thank you both for you time and efforts help me
-
thank you gizmola, clear worked like a dream. I'll also take a closer look at that article too
the layout is looking great thanks to you guys, but im still having the problem with z-index not working when applied to menu div. the .body-container has opacity: 0.7; but i want .left-container (menu) layer to come forward so the background doesn't appear through it like so
here is the updated html:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Dashboard</title> <link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <style> *{ font-family: 'Titillium Web'; } body { background:url("https://image.ibb.co/h93Ndo/abstract.jpg") top right no-repeat; background-attachment:fixed; margin: 0; margin-top: 10px; } .body-container{ position: relative; display: flex!important; flex-direction: column; justify-content: stretch; align-items: stretch; min-height: 99vh; margin: auto; width: 97%; opacity: 0.7; z-index: -1; } .header{ flex-grow: 0; background: #3A98FD; border-top-left-radius: 15px; border-top-right-radius: 15px; z-index: 1; height: 70px; } .two-cols{ flex-grow: 1; display: flex; flex-direction: row; justify-content: stretch; } .left-container{ position: relative; display: flex; flex-direction: column; justify-content: flex-start; flex-grow: 1; flex-basis: 13%; z-index: 1; background: #3B4A53; } .content{ display: flex; flex-direction: column; justify-content: space-between; flex-grow: 1; flex-basis: 85%; background: #ffffff; z-index: 1; vertical-align: text-top; vertical-align: top; } .clear{ clear: both; } </style> </head> <body> <div class="body-container"> <div class="header"></div> <div class="two-cols"> <div class="left-container">menu</div> <div class="content"> Content </div> </div> <div class="clear"></div> </div> </body> </html>
thank you for your help again guys!
-
that works much better thank you max.
when i try apply a margin to the top of the page it pushes the body down too...how can this be fixed please?
and also i tried to add z-index to the header and left container to stop bg image showing through but its also not work. (trying to get the bg image to only show through content div)
thanks again.
updated:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Dashboard</title> <link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <style> *{ font-family: 'Titillium Web'; } body { background:url("https://image.ibb.co/h93Ndo/abstract.jpg") top right no-repeat; background-attachment:fixed; margin-top: 10; } .body-container{ display: flex!important; flex-direction: column; justify-content: stretch; align-items: stretch; min-height: 100vh; margin: auto; width: 97%; opacity: 0.7; z-index: -1; } .header{ flex-grow: 0; background: #3A98FD; border-top-left-radius: 15px; border-top-right-radius: 15px; z-index: 1; } .two-cols{ flex-grow: 1; display: flex; flex-direction: row; justify-content: stretch; } .left-container{ display: flex; flex-direction: column; justify-content: flex-start; flex-grow: 1; flex-basis: 15%; z-index: 1; background: #3B4A53; } .content{ display: flex; flex-direction: column; justify-content: flex-end; flex-grow: 1; flex-basis: 85%; background: #ffffff; z-index: 1; } </style> </head> <body> <div class="body-container"> <div class="header">Here's the header</div> <div class="two-cols"> <div class="left-container">menu</div> <div class="content"> hello world </div> </div> </div> </body> </html>
-
I'm having trouble getting the .body-container and .left-container to follow suit with the .content, the height of both divs don't seem to alter down. Also z-index doesnt work on .left-container as im trying to stop the background to show through that particular div.
ive read it may be because of the absolue positioning. Any help on these matters would be great.
thank you<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <style> body { background:url("https://image.ibb.co/h93Ndo/abstract.jpg") top right no-repeat; background-attachment:fixed; margin: 0; } .body-container{ background-color: #ffffff; border-top-left-radius: 15px; border-top-right-radius: 15px; margin: auto; width: 98%; height: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0; opacity: 0.7; margin-top: 10px; } .header{ position:relative; display: block; width: 100%; background-color: #3A98FD; height: 70px; border-top-right-radius: 15px; border-top-left-radius: 15px; } .left-container{ display: block; color: #ffffff; float: left; background-color: #3B4A53; width: 12%; height: auto%; min-height: 100%; } .content{ position: absolute; display: inline-block; float: right; width: 100%; height: auto; min-height: 100%; } </style> </head> <body> <div class="body-container"> <div class="header"></div> <div class="left-container">menu</div> <div class="content"> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>hello world </div> </div> </body> </html>
-
you need a trigger
$(document).ready(function() { $('.trigger').click(function(){ $('input.player_search').typeahead({ name: 'player_name', remote: 'mysql.php?query=%QUERY', }); }); }) // the html trigger <button class="trigger">Search</button>
i see some big security risks with your php also...your database is open to sql injection, you need to get that sorted before putting your script live.
http://php.net/manual/en/mysqli.real-escape-string.php
if you used PDO instead of mysqli you probably wouldnt have this problem.
-
Thank you for your help...changing the int to string work perfectly
-
hey guys im tyring to pass a integer to a method and i get this error:
Invalid numeric literal
when using this code
$this->get_model('contract:contracts')->send_verification_pin(070000000000);
i could use quotes like so
$this->get_model('contract:contracts')->send_verification_pin('070000000000');
but then the integer has the 0 missing at the beginning...this is my debug
int(7000000000) /^07\d{9}$/ ["Phone Number: Invalid phone number."]
where is this missing 0 please guys?
thank you
-
i wouldnt of thought of that...thank you barand for your time and effort
-
well the tablet would't have a verfication pin...but i planned on having 1 table ie. network_contracts to hoild users contratcs such as sim only, mobile and tablet.
the verification pin is for when a user adds sim only / mobile, a pin is then sent to users phone number which needs to be verified.
-
hey guys im wanting to check if a row exists then update, else insert.
i've been trying to get this query to work, but i'm not having much luck...i know some of you will say to use ON DUPLICATE KEY and make column phone_number primary key but that won't work as contract type column could be TABLET which has no phone number.
IF EXISTS (SELECT network_contract_id FROM network_contracts WHERE phone_number = 123456 AND user_id = 1) UPDATE network_contracts SET verification_pin = 9891 WHERE user_id = 1 ELSE INSERT INTO network_contracts(user_id, phone_number, contract_type, verification_pin) VALUES (1, 123456, 'Sim Only', 7676)
any help/advise would be greatly appreciated.
thank you guys
-
thank you kicken for the useful information...i've look into purchasing a GSM Router and hopefully will go ahead with setting up my own gateway, but firstly i need to speak with the mobile network providers in the UK to ensure i'm not breaking any the T&C's by doing this.
seems like a simple process to set up the hardware, also i see some scripts online that can process the AT commands to the com device....not sure if this is any good though.
https://drive.google.com/file/d/0B0NgcxAkZSCHS2MzUEtQMWZYWUc0QmF0RzNBMUItck8wZUtR/edit
thanks again
-
hey guys, im wanting to send sms via php, but have no real know how or experience with it....and don't want to be throw my money into the wrong places.
i see there is a lot of companies out there where i can buy text bundles from and then use thier api to send an sms, which is great...but is there a way to cut the middle man out?
if not could someone recommend me a company?
thank you
-
Oh also Cross Site Scripting Attacks...hackers will have a field day on your server
-
You need to check $_GET['id'] exists...also your code is vulnerable to Cross-Site Request Forgery Atacks (CSRF) and SQL Injection
I'd suggest to use PHP PDO instead of the mysqli extension.
-
why would you want store html in a database?
what you need to do it store necessary data, such as article name, article, user_id, timestamp etc.
what parts are you struggling with so we can help you further?...creating a database table...using PDO?
-
$data = mysqli_query($con, $query) or die(mysqli_error());
I tried this now and earlier too but still the same issue!!!
try what jacques1 said
The code is fundamentally wrong. It seems you've taken a really old, really bad script with mysql_* function calls and just added an “i” everywhere. This doesn't work. You need to actually learn the mysqli interface (or rather: database programming in general).
Get rid of this or die(mysqli_error()) stuff. Why on earth would you want to show your database errors to your users? What are they supposed to do with this message? It only helps attackers interested in gaining information about your system.
The proper approach is to enable exceptions so that the PHP error handler can take care of the problem (assuming you've configured it correctly):
// make mysqli throw an exception whenever it encounters a problem $mysqli_driver = new mysqli_driver(); $mysqli_driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT; $database_connection = mysqli_connect($host, $user, $password, $database);
Stop putting PHP values straight into query strings. Never heard of SQL injections? The proper approach is to use prepared statements:
// use a prepared statement with placeholders to safely pass data to MySQL $member_stmt = $database_connection->prepare(' INSERT INTO members (username, email, password) VALUES (?, ?, ?) '); $member_stmt->bind_param('sss', $_POST['username'], $_POST['useremail'], $_POST['password']); $member_stmt->execute();
Apart from that, I strongly recommend you use PDO instead of mysqli. It's a lot more comfortable, and since you have to rewrite your code anyway, you might as well choose the best interface available.
-
what i also i should of mentioned is that you need to escape all user data using mysqli_escape_string() failure to do so can result in SQL injection
$username = mysql_escape_string($_POST['username']);
this wouldn't be a problem if you used PDO and prepared queries.
-
where should i make these changes??
thanks
seriously?...i just gave you the documentation referring to mysqli_query as well as the code for your first mysql insert
$data = mysqli_query ($query)or die(mysqli_error());
should be
$data = mysqli_query($con, $query) or die(mysqli_error($con));
i'm more than sure you can work out the other...if not, give up
but i would suggest to use PDO http://php.net/manual/en/book.pdo.php
date to mon - fri
in MySQL Help
Posted
thank you for your quick reply. i would also need friday's date.
ive been testing via sql, and think ive almost made a breakthrough, but i get an error.
SELECT DATE_ADD(DATE('2018-08-14'), INTERVAL - WEEKDAY(DATE('2018-08-14')) DAY) AS 'week_start', DATE_ADD(week_start, INTERVAL 5 DAY) AS 'week_end'