Incidentally does it disguise the user agent at all or will it get blocked by websites that aren't specifically set up to be scraped? Or rather, haven't bothered blocking non-standard browsers. I'm not even sure what the legality or general consensus for that is. I know that google search results frown heavily on scraped content but whether the host website can say "Hey you're scraping my poo poo and I specifically didn't give authority" and have that mean anything, or what, is beyond me... I mean some people specify "this content is from X source" but what's the deal with reproduction there? On some level you'd expect it to have the same rules as copyrighted works, but you can quote those and re-use parts of those for various purposes legally, so long as you attribute it. I've put myself into mode on friday night Sulla Faex fucked around with this message at 19:25 on Sep 5, 2014 |
|
# ? Sep 5, 2014 19:22 |
|
|
# ? Jun 7, 2024 19:40 |
|
Sulla-Marius 88 posted:Incidentally does it disguise the user agent at all or will it get blocked by websites that aren't specifically set up to be scraped? Or rather, haven't bothered blocking non-standard browsers. I tried your code and it worked perfectly. Thanks. I should have tried reading the documentation instead of just reading the examples. Yeah, I'm not too sure on the legality of it. In this particular case, I have the permission from the website server
|
# ? Sep 5, 2014 19:36 |
I don't mean to presume, not sure how your PHP is, but I thought I'd mention that, as you're using a foreach to iterate through multiple expected elements (ignoring that your code example uses a unique #image identifier), if there really are multiple results, the variable $myImageUrl will only ever contain the last definition. If you're expecting multiple results, add each one to an array or process it on the spot, etc. I imagine you were just throwing together a quick example and it's not exact code but I figured I'd throw it out there just in case.
|
|
# ? Sep 5, 2014 20:05 |
|
A little back-story. I am building an app using Laravel 4.2 that requires users to be able to authenticate. The authentication piece works great, now I want to restrict access to objects by roles. Each user will be a member of an account. Each account can have multiple users assigned to it with different roles. These relationships are defined in the memberships table. Using the id from the memberships table, I want to assign roles to that relationship. I want to keep the roles in a separate table and link the roles in a table called membership_roles. I'm not entirely sure this is the best possible way to do it, so in addition to looking for some help accomplishing this task, I want to do it in the best possible way. Database design is not one of my strong skills and I always over-think it. pre:Joe Blow has an account called Joe's account Joe is an Admin of this account John is a User of this account John Doe has an account called John's account. John is an Admin of this account Joe is also an Admin of this account pre:users id - integer email - string password - string accounts id - integer display_name - integer memberships id - integer user_id - integer account_id - integer roles id - integer name - string membership_roles id - integer membership_id - integer role_id - integer php:<? $user = User::first(); $account = $user->memberships->first(); $results = DB::table('users') ->join('memberships', 'memberships.user_id', '=', 'users.id') ->join('membership_roles', 'membership_roles.membership_id', '=', 'memberships.id') ->join('roles', 'roles.id', '=', 'membership_roles.role_id') ->where('users.id', '=', $user->id) ->where('memberships.account_id', '=', $account->id) ->select('roles.name') ->get(); return $results; ?> code:
I see lots of discussion about Laravel here, I know someone else has faced this same issue. Edit: When a user logs in, I need to generate a list of accounts they have permission to access. $my_accounts = [ 1, 2, 3, 4 ]; //simplified... Currently I use this method in the User model: php:<? /* in the controller */ $accounts = Auth::user()->memberships; /* in the User model */ public function memberships() { return $this->belongsToMany('Account', 'memberships')->withTimestamps(); } ?> They may have "user" access to one account and "Admin" access to another. route = /accounts/view/1 $account_roles = [ 'admin' ]; // generate an array of roles for the requested account and logged in user. If a user views an account, I want to limit the ability to add, change or delete features if they don't have the proper role. Switching to a different account will load the roles the user has on that account. On any given page or account, I need to know if the user can even view that account or if I should redirect to a 403 page. Example: User 1 can access Account 1 only /accounts/view/1 will work /accounts/view/2 will 403 If the user only has read access to account 1, the following will also 403 /accounts/edit/1 mooky fucked around with this message at 16:16 on Sep 6, 2014 |
# ? Sep 6, 2014 04:51 |
|
Hello PHP thread. I don't know if this is exactly the place to ask this question but I'm going to do it anyway. Basically, I've made a simple Laravel app and I want to put it up on the webs. However, the catch is that I want it to live in a subdirectory. I am running nginx as the webserver and nothing I've found on Google so far has worked. The best I've had is it partly working displaying the home page but with none of the other routes available, and then I raged and deleted the configuration because it had been hours. Does anyone here know how I'd go about doing this? I have no interest in trying a subdomain and I can't put it on the root of the domain, I want it in a subdirectory. It seems that no one generally has any interest in doing this and has all their apps on separate domains. Thanks for any help xoxoxo
|
# ? Sep 10, 2014 20:06 |
TheDukeOfFail posted:Hello PHP thread. I did this recently, not with Laravel specifically though, it was a different PHP app. code:
|
|
# ? Sep 10, 2014 20:15 |
|
fletcher posted:I did this recently, not with Laravel specifically though, it was a different PHP app. You are my saviour. I've been doing this all day without success and now it works flawlessly! The I spent all that time ago was worth it just for this.
|
# ? Sep 10, 2014 20:41 |
TheDukeOfFail posted:You are my saviour. I've been doing this all day without success and now it works flawlessly! Awesome! Glad to hear that it worked. I was banging my head against it for days with no success...I was so relieved when I finally got it working.
|
|
# ? Sep 10, 2014 20:46 |
|
I guess I should mention for anyone else reading that I had to change the socket, so fastcgi_pass unix:/var/run/php-fpm-www.sock; became fastcgi_pass unix:/var/run/php5-fpm.sock;. Everything else was left as-is beyond the obvious changing things to my actual site/subdirectory. Edit: Running Ubuntu 14.04 Chunks Hammerdong fucked around with this message at 21:22 on Sep 10, 2014 |
# ? Sep 10, 2014 21:20 |
|
So I am at what I would call an "Intermediate" level of knowledge of PHP and OO design. I have a good grasp of SQL commands as well for working with my DB. Recently I was watching a video on PHPAcademy for creating a user login section of my site and I saw him developing a DB wrapper. While I get the general gist of it, I seemed to get a little lost in what exactly he was doing. Most specifically it was the stuff relating to creating an instance of the DB. He stated that by creating an instance of the DB, it would cut down on connections between the server and the client. Is this because when the instance of the DB class is made the connection persists throughout the life of the browser window being open (if I choose to never close the connection on the bottom of my page will this also be the case?)? Because otherwise it seems like you'd still be making a connection to the server over and over again. Sorry for the dumb question. EDIT: I see that he made the $_instance variable static. I'm guessing that is what is cutting down connections? Windows 98 fucked around with this message at 16:55 on Sep 12, 2014 |
# ? Sep 12, 2014 16:49 |
|
So by creating a database object and initiating the connection in its constructor, you avoid making a connection manually every time you want to run a query. If you have five queries that run on a pageload, this allows you to reuse the connection for all five. Connections will not persist between pageloads (unless you use a lib/framework that persists connections). Really though you should be using something like Laravel that comes with excellent db manipulation tools built-in. No need to reinvent the wheel unless it's for learning purposes.
|
# ? Sep 12, 2014 17:12 |
|
Ok. That makes sense, I understand what is happening now. Thank you very much. I will have to watch the videos they have Laravel, looks pretty sweet
|
# ? Sep 12, 2014 17:59 |
PHPStorm 8 was released the other dayquote:We’re happy to announce the release of PhpStorm 8, the newest version of our IDE for PHP and web development. PhpStorm 8 brings even more emerging technologies to help you enjoy web development, with deepest-ever code understanding and advanced support for remote environments: Pretty awesome stuff imo
|
|
# ? Sep 17, 2014 16:11 |
|
I have this problem I'm not sure how to go about. If there is another programming language I should also use, I'd appreciate any insight, or stuff I can look into. I have a form that when submitted, creates a custom spectrogram. Depending on the dates a person submits, the spectrograms could take from 10 seconds to about 5 minutes (maybe longer). The spectrograms work, but some people are closing the browser window when they feel it's taking too long, even if I have a loading bar. my questions are: Can I send an email out when the process is done? Would that just be, doing a php email send after the process is completed? Even if the browser has been closed? Also, is there any easy to show a process timer? Well, this may be harder since I really do not know how long a certain spectrogram takes, but how about a timer that shows how much time has taken? I think my questions are broad, so I apologize for that; I'm trying to figure the best way to tell a user that it may take a bit. Any help is appreciated.
|
# ? Sep 17, 2014 16:50 |
stoops posted:I have this problem I'm not sure how to go about. If there is another programming language I should also use, I'd appreciate any insight, or stuff I can look into. Adding a loading bar should be pretty straight forward, but you're definitely going to have to dive into JavaScript a bit. Basically you want to use Javascript to send the data, display the loading icon, and then display the image once the process has been completed. This can be a bit daunting if you've never done it before but it's certainly possible.
|
|
# ? Sep 17, 2014 17:36 |
|
stoops posted:I have this problem I'm not sure how to go about. If there is another programming language I should also use, I'd appreciate any insight, or stuff I can look into. Not sure of your server architecture, but you definitely want to look into something like Resque to handle background processing.
|
# ? Sep 17, 2014 18:06 |
|
Couple ways to do progress bars. If you have an idea how long the load time generally is you can take that number and add say, 45% to it, and use JS to move the progress bar and then when your data comes back you fire off a callback that triggers a faster movement to completion. Coupled with the right easing setting, this has a really really slick effect because it acts like people expect a progress bar to; it chugs for a bit, then zooms off towards the end and finishes. There's some psychological satisfaction with the way it finishes and returns data. Anyway, if your times vary by super-huge amounts this might not always work but you can always crank the initial delay up as needed, you just lose some of the effect. Other methods of doing a progress bar would be to monitor how long the data takes to process and store the statistics on it. Then have the server monitor these stats and send out intelligent progress bar timing values to calibrate your frontend with. There are also some ways (long-polling, timed callbacks) that you can actually update the client in somewhat realtime but there is a lot more complexity involved.
|
# ? Sep 17, 2014 18:59 |
|
I am getting this error from a red hat apache environment which is running php with a Kohana application. This application was migrated from a wamp installation where it was functioning. Currently if I hit the following URL I get a 404 error http://server/home But if I hit this the page renders http://server/index.php/home I assume this has to do with my .htaccess files, but I have been unable to resolve the issue. Below is the .htaccess file found in apache/htdocs where my application resides code:
code:
php:<? Kohana::init(array( 'base_url' => '/', 'index_file' => FALSE, )); Route::set('default', '(<controller>(/<action>(/<id>)))') ->defaults(array( 'controller' => 'welcome', 'action' => 'index', )); ?> Loaded moudles from php_info() code:
|
# ? Sep 26, 2014 19:37 |
|
Looks like you have the rewrite rule that routes index.php commented out... # Rewrite all other URLs to index.php/URL #RewriteRule ^(.*)$ index.php/$1 [PT]
|
# ? Sep 26, 2014 22:00 |
|
Are there any good PHP libraries or frameworks for large batch or background processes? I need to do a fairly simple process, probably anywhere from 100 to 10,000 times.
|
# ? Sep 27, 2014 17:09 |
|
Mogomra posted:Are there any good PHP libraries or frameworks for large batch or background processes? I need to do a fairly simple process, probably anywhere from 100 to 10,000 times. Gearman and PHP Resque are probably the two most common. I've never used Gearman, and Resque is awesome.
|
# ? Sep 27, 2014 23:18 |
|
Those look great, thanks for the links!
|
# ? Sep 28, 2014 00:31 |
|
I decided this is the weekend to start learning PHP and am having some trouble with XAMPP installation for windows. Do I need to install Tomcat if I just want this for PHP/MySQL development? I tried installing it once and ran into problems where it was conflicting with already installed Java, and I'd really just as soon not bother. Raskolnikov2089 fucked around with this message at 02:51 on Sep 28, 2014 |
# ? Sep 28, 2014 02:44 |
|
Raskolnikov2089 posted:I decided this is the weekend to start learning PHP and am having some trouble with XAMPP installation for windows. No, you don't need Tomcat. Though if you're going to be eventually working with a Linux environment, you might as well use PuPHPet to generate a vagrant and puppet manifest. It's really easy. If you're a bit more involved, using vagrant with rsync is preferable to NFS on Windows in VirtualBox.
|
# ? Sep 28, 2014 03:11 |
|
Raskolnikov2089 posted:I decided this is the weekend to start learning PHP and am having some trouble with XAMPP installation for windows. spacebard is right, unless you're deploying to a Windows server, definitely spend the few hours and learn basic Vagrant usage to work on a Linux box. There also Phansible if you prefer Ansible over Puppet, and we released our own pre-built .box files: https://github.com/brightmarch/vagrant-box if you just want to get started (note: we use Postgres only, so they don't come with MySQL, but they're Ubuntu boxes so installing MySQL would be easy).
|
# ? Sep 28, 2014 12:21 |
|
revmoo posted:Looks like you have the rewrite rule that routes index.php commented out... I had uncommented out that line on the .htaccess which is at the apache/htdocs level. However the issue persisted. Since the server/index.php/home routing is working. It seems like the RewriteRule is not functioning...
|
# ? Sep 30, 2014 14:37 |
|
Do you have mod rewrite enabled? (a2enmod rewrite; apachectl restart)
|
# ? Sep 30, 2014 14:47 |
|
Yes rewrite mode was enabled. As it turned out the issue was with the httpd.conf in apache. configuring this allowed the application to work . <Directory "/www/"> Options All AllowOverride All Require all granted </Directory>
|
# ? Sep 30, 2014 16:04 |
|
Ahh yes the AllowOverride thing has caught me out many times
|
# ? Sep 30, 2014 18:56 |
|
Nevermind, figured my question out. Turns out !== is not !=
my bony fealty fucked around with this message at 21:29 on Oct 1, 2014 |
# ? Oct 1, 2014 20:32 |
|
Never edit out your questions.
|
# ? Oct 1, 2014 23:51 |
|
I am new to Laravel and I have run into an issue that when I try passing an object to a view, it is converted into a __PHP_Incomplete_Class Object, which means that the data was sent, but I am unable to reference it inside of the view (e.g. {{ $orders->order_date }} does not print out the order_date). This is the controller code that I am using: php:<? class OrderController extends BaseController { public function getOrderStep1() { return View::make('orders.orderStep1'); } public function postOrderStep1() { $validator = Validator::make(Input::all(), array( 'first_name' => 'required', 'last_name' => 'required', 'address1' => 'required', 'address2' => '', 'city' => 'required', 'state' => 'required|max:2', 'postal_code' => 'required|min:5|max:10' ) ); if ($validator->fails()) { return Redirect::route('orders-step1-post')->withErrors($validator)->withInput(); } else { // Process the form data // Create account $first_name = Input::get('first_name'); $last_name = Input::get('last_name'); $address1 = Input::get('address1'); $address2 = Input::get('address2'); $city = Input::get('city'); $state = Input::get('state'); $postal_code = Input::get('postal_code'); // Accesses the Customer model // Create is defined in eloquent $customer = Customer::create(array( 'first_name' => $first_name, 'last_name' => $last_name, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'state' => $state, 'postal_code' => $postal_code, 'customer_status_id' => 20 )); if ($customer->save()) { // Should create the order after the customer has been created. Will need to think // about creating order when the customer already exists. $order_date = DB::raw('CURRENT_TIMESTAMP'); $source_code = 'TEST'; $user_id = Auth::user()->id; $customer_id = DB::table('customers')->max('customer_id'); // Accesses the Order model // Create is defined in eloquent $order = Order::create(array( 'order_date' => $order_date, 'source_code' => $source_code, 'user_id' => $user_id, 'customer_id' => $customer_id )); $order_id = DB::table('orders')->max('order_id'); if ($order->save()) { // Directs the user to the orderStep2 view and passes the $order object to the view. // Global will be a global message area in our template $orders = Order::find($order_id); $orders = $orders->first(); /** * This is where I redirect to the getOrderStep2() function and pass the $orders object */ return Redirect::route('orders-step2')->with('global','The customer and order has been created.')->with('orders',$orders); } else { // Returns user to the home route and displays an account creation message // Global will be a global message area in our template return Redirect::route('home')->with('global','The customer has been created.'); } } return Redirect::route('home')->with('global','Error: The customer has not been created.'); } } /** * This is where I send the object to the view, I suspect that getting it from the session might be part of the problem. **/ public function getOrderStep2() { return View::make('orders.orderStep2')->with('orders', Session::get('orders')); } } ?> code:
{{{ $orders->order_date }}} Then it yields the following error: quote:main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Order" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition (View: C:\xampp\htdocs\Laravel_Auth\fresh\app\views\orders\orderStep2.blade.php) Is there a different way that I should try passing the object to the view, so that it is actually usable inside of the view? I've figured out a fair amount of Laravel, but this is one aspect that seems really strange to me. Thank you very much in advance. php:<? public function getOrderStep2() { return View::make('orders.orderStep2')->with('orders', Session::get('orders')); } ?>
|
# ? Oct 2, 2014 01:30 |
|
Change php:<? return Redirect::route('orders-step2')->with('global','The customer and order has been created.')->with('orders',$orders); ?> php:<? return Redirect::route('orders-step2', array($orders))->with('global','The customer and order has been created.'); ?> php:<? public function getOrderStep2() { return View::make('orders.orderStep2')->with('orders', Session::get('orders')); } ?> php:<? public function getOrderStep2($orders) { return View::make('orders.orderStep2')->with('orders', $orders); } ?> You're essentially sending the $orders as a Flash object which is not the way you want to do it. Let me know if this doesn't work and I'll help you out. DarkLotus fucked around with this message at 15:27 on Oct 2, 2014 |
# ? Oct 2, 2014 04:49 |
|
Aniki posted:laravel stuff You should also look into using vagrant for laravel dev instead of XAMPP... https://laracasts.com/search?q=vagrant
|
# ? Oct 2, 2014 04:57 |
|
Aniki posted:Laravel stuff How have you found Laravel for making what I'm assuming is an e-commerce site? I'm just getting into it, watching all the Laracasts I can handle and really like it. Its got me interested in PHP again when I was on the fence about jumping over to Ruby or Python.
|
# ? Oct 2, 2014 11:39 |
|
DarkLotus posted:Change Ok, I updated the code with your recommended changes and Laravel threw a 403 error: quote:Access forbidden! I do have an authentication/login system in place based on phpacademy's Laravel 4 Authentication guide, but the path it direct me to is really strange. It repeats the first 4 levels of the directory structure, but it does include the object: code:
quote:ErrorException (E_UNKNOWN) Which would be this section of code: php:<? public function getOrderStep2($orders) { return View::make('orders.orderStep2')->with('orders', $orders); } ?> php:<? $orders = $orders->first(); ?> Edit: Do I need to make any changes to the route if getOrderStep2 is going to accept the $orders object? php:<? Route::get('/orders/step2', array( 'as' => 'orders-step2', 'uses' => 'OrderController@getOrderStep2' )); ?> Aniki fucked around with this message at 19:49 on Oct 2, 2014 |
# ? Oct 2, 2014 19:20 |
|
DarkLotus posted:Also, sign up at https://laracasts.com/ it's worth it! I will definitely check out Laracasts. I started off learning Laravel through phpacademy's Laravel 4 Authentication guide, so learning by example through videos works well for me. I'll take a look at vagrant. I was just using XAMPP, since it's what I've used in the past for setting up test servers. Heskie posted:How have you found Laravel for making what I'm assuming is an e-commerce site? It is actually going to be in house call center software, but I am just doing proof of concept work right now to make sure that I am comfortable working with Laravel. I've also been on the fence about moving on from PHP, I have spent some time looking into Ember and Node.js since I really wanted to start developing MVC applications, but they just weren't clicking with me even though I have pretty good understand of jQuery. I actually came across Laravel, because I was doing research on writing a secure login page for this project and it quickly became apparent that writing all of the security code on my own would have been a hopeless endeavor and Laravel makes it very easy. I also like how easy they make it work with forms, especially for things like validation and CSFR protection. The thing that really sold me on Laravel is the Eloquent ORM. It is just such a nice and clean way to work with querying and managing database records and I like that I can still write traditional queries when needed. Honestly, the Eloquent ORM would be reason enough for me to use Laravel. I know there will be challenges with me learning a new framework and getting my head around the nuances of MVC, but I needed to do this at some point and this seems like a good fit for me right now.
|
# ? Oct 2, 2014 19:47 |
|
Aniki posted:Ok, I updated the code with your recommended changes and Laravel threw a 403 error: Wow, looking back, I shouldn't have replied while tired... What you want to do is persist the order to your database or whatever, then pass the $order->id on to the next method like this php:<? return Redirect::route('orders-step2', array($orders->order_id))->with('global','The customer and order has been created.'); ?> php:<? Route::get('/orders/step2/{order_id}', array( 'as' => 'orders-step2', 'uses' => 'OrderController@getOrderStep2' )); ?> php:<? public function getOrderStep2($order_id) { $orders= Order::find($order_id); return View::make('orders.orderStep2')->with('orders', $orders); } ?> DarkLotus fucked around with this message at 20:03 on Oct 2, 2014 |
# ? Oct 2, 2014 20:00 |
|
DarkLotus posted:Wow, looking back, I shouldn't have replied while tired... Not a problem at all. Those changes work perfectly and I was even able to clean it up further since I am already grabbing the max order_id outside of the if ($order->save()) block: php:<? $order_id = DB::table('orders')->max('order_id'); if ($order->save()) { // Removed $orders = Order::find($order_id) since it was redundant return Redirect::route('orders-step2', array($order_id))->with('global','The customer and order has been created.'); } ?>
|
# ? Oct 2, 2014 20:22 |
|
|
# ? Jun 7, 2024 19:40 |
|
So I just got a new job working with Magento recently, which I've used in very limited capacities before, but I'm going to be jumping head-first into modules and templates, and I have a pretty good grasp on everything except how to make any loving sense at all of a layout XML file. I thought I understood OOP and namespaces but I guess I'm just retarded I am, primarily, a Django developer, so having to explicitly define so many things and rely on namespaces really throws me through a loop. Right now I have a module, ModTest, which resides in the LearningStuff namespace. All I'm trying to do is wrap a simple template with the base header/footer and I have no idea how to make sense of this XML poo poo. I thought I had some sort of clue what I was doing, until I tried to unset references to two sidebars and make a single-column layout, but unsetting the children did approximately dick and I wouldn't think I was doing anything at all if I couldn't see the base templates rendering when I go to my module's URL. Can anyone possibly give me a code sample of a simple Magento layout, and how I would produce the same thing in Django? If I could see the two side-by-side, I feel like it'd make a ton more loving sense, but as usual I'm the only Python guy around EDIT: I found this and it's amazing. Like, I found the PDF for free, and then turned around and bought it anyway because it's the only Magento template tutorial on the entire internet that's worth a drat, apparently. DICTATOR OF FUNK fucked around with this message at 07:59 on Oct 3, 2014 |
# ? Oct 3, 2014 07:21 |