Jump to content

maxudaskin

Members
  • Posts

    628
  • Joined

  • Last visited

Everything posted by maxudaskin

  1. Hello all and happy holidays! I am having a brain fart with my regex and cannot seem to wrap my head around what I am doing wrong. $regex = '/(?:<thead><tr>)(<th>(.*)<\/th>)+(?:<\/tr><\/thead>)/'; $subject = '<thead><tr><th>Day</th><th>Date</th><th>Duty</th><th>From</th><th>Report</th><th>To</th><th>Release</th><th>Flight Time</th><th>Duty Time</th><th>TAFB Time</th><th>Rest Time</th><th>Sector(s)/Event(s)</th></tr></thead><tbody>...more string'; What I am hoping to get out of this is ['Day', 'Duty', 'From', 'Report',] // ... and so on But I'm getting this instead Array( '<thead><tr><th>Day</th><th>Date</th><th>Duty</th><th>From</th><th>Report</th><th>To</th><th>Release</th><th>Flight Time</th><th>Duty Time</th><th>TAFB Time</th><th>Rest Time</th><th>Sector(s)/Event(s)</th></tr></thead>', '<th>Day</th><th>Date</th><th>Duty</th><th>From</th><th>Report</th><th>To</th><th>Release</th><th>Flight Time</th><th>Duty Time</th><th>TAFB Time</th><th>Rest Time</th><th>Sector(s)/Event(s)</th>', 'Day</th><th>Date</th><th>Duty</th><th>From</th><th>Report</th><th>To</th><th>Release</th><th>Flight Time</th><th>Duty Time</th><th>TAFB Time</th><th>Rest Time</th><th>Sector(s)/Event(s)', )
  2. <?php // FlightEntryController.php ... class FlightEntryController extends Controller { public function __construct() { $this->authorizeResource(FlightEntry::class); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(FlightEntry $flight) { dd($flight); } ... } // FlightEntryPolicy.php class FlightEntryPolicy { use HandlesAuthorization; ... /** * Determine whether the user can view the model. * * @param \App\Models\User $user * @param \App\Models\FlightEntry $flightEntry * @return \Illuminate\Auth\Access\Response|bool */ public function view(User $user, FlightEntry $flightEntry) { dd($user); if($user->hasPermissionTo('view flights not owned')) { // Spatie return Response::allow(); } if($user->id === $flightEntry->user_id) { return Response::allow(); } return Response::deny(null, 404); } ... } // AuthServiceProvider.php class AuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. * * @var array */ protected $policies = [ App\Models\FlightEntry::class => App\Policies\FlightEntryPolicy::class, ]; ... } // routes/web.php Route::resource('/flights', FlightEntryController::class)->middleware('auth'); With the policy not attached, everything works fine. When I attach the policy, index (viewAny) works, but show (view) does not. It throws a 403 and does not run the dd inside. I'm going crazy. Any suggestions?
  3. Turns out OpenCart has been modifying the source and adding an additional } that is creating a syntax error. Off to find the root of this issue.
  4. Hi guys, I'm customizing an OpenCart template that is riddled with programming bugs. It is MVC and I am having a really odd issue with a controller file. The template that I want to use is not loading. I have edited the one in the selected template and also the default, but no avail. I was troubleshooting why it wasn't working and I came to the conclusion that either I am completely blind or stupid, or PHP is all of a sudden a troll. Please let me know if you need more context, but here is a snippet of the code and the result. I am really at a loss right now. Result: 14 Code: echo "1"; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) { echo "2";die(); $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category.tpl', $data)); } else { echo "3";die(); $this->response->setOutput($this->load->view('default/template/product/category.tpl', $data)); } echo "4";die();
  5. My suggestion is to seperate the active users data from the users themselves. Have a second table that is queried to find the last page load activity. This way you can, if you want, log all of the user's actions, login's, or none of them at all.
  6. You have to link to the image relative to the file that the user first loaded. If they loaded http : //www . example . com/dir/abcd/efg/index.php, and the image was in /dir/upload, you would have to either call the image relatively, ../../upload/image.jpg or absolutely, http : //www . example . com/dir/upload/image.jpg.
  7. I would create a cron job running once a day, calling a php script. The php script would get the rows from the table from x days ago and would loop through and send a follow up email. Have each email template in it's own file. Let's say, initial_email.php and followup_email.php. <?php /** * initial_email.php */ $message = <<<EOD Hi {$name}, Thank you for submitting your information. You will receive an email in about seven days. --- This is an automated email. Replies will not be received. EOD; <?php /** * followup_email.php */ $message = <<<EOD Hi {$name}, About a week ago, you entered your information into our system. This is the follow up email. --- This is an automated email. Replies will not be received. EOD;
  8. The best way to prevent header errors is to, instead of putting php in the middle of html code, separate your code into three main catagories Models Views Controllers Models are the liaisons between your code and databases, xml files, ect. Use functions such as get_posts, save_post, remove_post. Views are the files containing the HTML code. The only php on the page should be to output data. <h1>Posts</h1> <?php foreach($posts as $post): ?> <div> <?=$post?> </div> <?php endforeach; ?> Controllers control the data that is being sent to the views. Let's say that a user wants to view a post. Controller is activated. Controller gets the id of the post from the URI, $_GET['id'] Controller asks the Model for the post from the database. $model->get_post($id); Model runs get_post. Queries the database for a post with a 'post_id' of $id Model either returns the post data, or false if it didn't find anything Controller gets the post data. Checks if false. If false, returns a 'Post Not Found' error. Controller sends the post data to the View file. View echoes the post data. User reads the article and goes about the rest of their day, none the wiser. Here's some reading material. It is a bit lengthy.
  9. http://www.php.net/manual/en/function.array-multisort.php#example-4608
  10. Very ineffective salting method. Try this: function enc_salt($password) { $salt = 'somerandomecharacters1646#s@0-2 da2e/5ad+'; return md5($password . $salt); }
  11. Change if(file_put_contents($logfile, $data, FILE_APPEND)) { } else { echo "logfile could not be accessed"; } to if(!file_put_contents($logfile, $data, FILE_APPEND)) { echo "logfile could not be accessed"; }
  12. That's purely an HTML and CSS question... erm... statement.
  13. Real quick, I'm going to show you something to save your butt, then I'll try to explain how to do this. What is it exactly is it that you need help with? If you're looking to get code written for you, then you'll have to go to the Freelance Section. If you're looking for assistance with code that you're writing, you'll have to let us know what you need help with.
  14. I would highly suggest checking out PHPMailer.
  15. I used the literal string keys because it's doubtful that the keys will change. I think that he's trying to find a way to use the array, not just output everything in it.
  16. What he said. But just in case you want code to learn from, here you go The two output the exact same thing, but the method is different. First one answers your question directly. <?php $myarray = array( array( 'color' => 'black', 'animal' => 'cat', 'state' => 'Wyoming', 'food' => 'Lasanga'), array( 'color' => 'yellow', 'animal' => 'lion', 'state' => 'Winnipeg', // I'm Canadian. Got a prooblem? 'food' => 'Pizza'), array( 'color' => 'green', 'animal' => 'Giraffe', 'state' => 'New York', 'food' => 'Potatoes')); // Let's output this data... simply. foreach ($myarray as $key=>$player) { echo 'Player ' . $key . ': '; echo 'color: ' . $player['color'] . ', '; echo 'animal: ' . $player['animal'] . ', '; echo 'state: ' . $player['state'] . ', '; echo 'food: ' . $player['food']; echo '<hr />'; } //////// // The break between outputs... no significance in the code echo '<br /><br /><br /><br />'; //////// // What if you wanted something a little more... in depth? class Player // Player class... indivdual player { private $number; private $color; private $animal; private $state; private $food; function __construct($arr, $num) // The constructor { $this->number = $num; $this->color = $arr['color']; $this->animal = $arr['animal']; $this->state = $arr['state']; $this->food = $arr['food']; } function getAll() // Return all of the variables, parsed, as a string { $out = 'Player ' . $this->number . ': '; $out .= 'color: ' . $this->color . ', '; $out .= 'animal: ' . $this->animal . ', '; $out .= 'state: ' . $this->state . ', '; $out .= 'food: ' . $this->food; return $out; } } class Player_Roster // Player_Roster class { private $players; // List of player objects function __construct($players) // Constructor { foreach($players as $key=>$player) { // Create a list of Player objects $this->players[] = new Player($player, $key); } } function getAllToString() // Return all of the player objects, as a string { $out = ''; foreach($this->players as $player) { $out .= $player->getAll(); $out .= '<hr />'; } return $out; } } $players = new Player_Roster($myarray); // Create the new roster echo $players->getAllToString(); // Echo the list of players
  17. You missed this part: You are correct. Most of us will likely never need to optimize such small numbers, but to teach good habit is crucial to, let's say, Facebook using 100,000,000 hours of processing time per year vs. 95,000,000 per year. Yes, those numbers are fictional, and yes, the statistics say that it's only 5%, but when you are talking about 5% over 100,000,000 hours, it's still 5,000,000 hours. 5,000,000 dollars. 5,000,000 starving children dead. 5,000,000 something.
  18. It wasn't me. You did the work. I only gave you the spark.
  19. That will result in malformed SQL; WHERE tbl_components.ID = '1' WHERE tbl_components.ID = '2' WHERE tbl_components.ID = '3' Well, that's your problem. $val is going to be an Array. I can't really help because I still don't have any idea what you're trying to do. I don't know where $results_done is coming from, and I don't know what method you are using to get data to your script.
  20. This doesn't solve anything. You still need to determine which large image is associated with which small image. Negative. It automatically makes a thumbnail using javascript.
  21. If you want one SQL, try this. <?php $beginning = true; $sql_where = ''; foreach($results_done as $key => $val) { switch($key) { case 1: $q_cat = 4; break; // Without this statement, the page would continue checking the other cases, albeit, they would all get evaluated as false case 2: $q_cat = 1; break; case 3: $q_cat = 11; break; case 4: $q_cat = 2; break; case 5: $q_cat = 10; break; case 6: $q_cat = 9; break; default: // If the key is not 1-6, have a fallout. You can log the error, or do whatever you want. $q_cat = -1; } if(!$beginning) { $sql_where .= ' OR'; } else { $beginning = false; } $sql_where .= ' WHERE tbl_components.ID = \'' . $val . '\''; } $sql = 'SELECT `tbl_component_categories.ID`, `tbl_component_categories.folder_path`, `tbl_component_categories.comp_cat_name`, `tbl_components.component_name` FROM `tbl_components` JOIN `tbl_component_categories` on $q_cat = tbl_component_categories.ID'; $sql .= $sql_where; $query_cats = mysql_query($sql); if (!$query_cats) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query_cats; die($message); } while ($row = mysql_fetch_array($query_cats)) { echo $row['comp_cat_name'].": ".$row['component_name']."<br />"; }
  22. Check out Lightbox 2. It's free, requires no PHP, and will make your website look awesome!
  23. echo '<a href="large_image.php?i=' . $info['image_id'] . '"'>; echo "<p><img src=".$info['thumb_path']."></p>"; echo '</a>'; And in large_image.php, query the database for the image with an id of $_GET['i']
  24. Instead of using a comparison, use empty().
×
×
  • 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.