jeudi 21 avril 2016

HTTPS Nginx Configuration for Laravel 5

I currently have an HTTP laravel 5 app. The app is functioning fine. I'm trying to move to HTTPS. I already bough the cert, and here is my

Nginx Configuration

#HTTPS
server {

        listen 443 ssl;
        server_name my-site.com;
        ssl on;
        ssl_certificate /etc/ssl/my-site.crt;
        ssl_certificate_key /etc/ssl/my-site.key;

        root /usr/share/nginx/my-app/public;
        index index.php index.html index.htm;

        location / {

                try_files $uri/ $uri /index.php?$query_string;
        }

        location ~ \.php?$ {

                try_files $uri =404;
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_read_timeout 300;
                fastcgi_intercept_errors on;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                #Prevent version info leakage
                fastcgi_hide_header X-Powered-By;
                proxy_read_timeout 300;

        }

}

#HTTP
server {

        listen 80;
        server_name my-site.com;
        rewrite ^/.*$ https://$host$request_uri? permanent;
        return 301 https://$host$request_uri;

        #More Settings ..

        #root /usr/share/nginx/my-app/public;
        #index index.php index.html index.htm;

        #location / {

                #try_files $uri/ $uri /index.php?$query_string;
        #}

        #location ~ \.php?$ {

                #try_files $uri =404;
                #include fastcgi_params;
                #fastcgi_pass 127.0.0.1:9000;
                #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                #fastcgi_read_timeout 300;
                #fastcgi_intercept_errors on;
                #fastcgi_split_path_info ^(.+\.php)(.*)$;
                ##Prevent version info leakage
                #fastcgi_hide_header X-Powered-By;
                #proxy_read_timeout 300;

        #}

}


Now with this settings, I am one step closer,

I can see that when I go to : my-site.com

It redirect to https://my-site.com

But however, I won't be able to log-in at all. It kept bouncing me back out.


Do I need to adjust anything in my Laravel route ?

How do I prevent this from happening ?

How do you guys host your Laravel app in HTTPS ?


Any hints / suggestions on this will be much appreciated !



via Chebli Mohamed

[Unable to find the socket transport "TLS" - did you forget to enable it when you configured PHP? #32673]

I'm facing the following message when sending email through Zoho SMTP server.

[Unable to find the socket transport "TLS" - did you forget to enable it when you configured PHP? #32673]

I tried looking for opennssl support on my PHP installation and it seems everything is OK.

My phpInfo() says that the TLS stream are registered and openssl extension enabled.

I'm using Laravel 5.1 on a ubuntu server 14.04 on Digital Ocean and PHP 5.6.20. I google for a solution but I just found answers for Windows OS.



via Chebli Mohamed

Generating Unique Receipt Codes in Laravel

Hello in my laravel application I have a function that generates a unique receipt code whenever a customer completes a transaction.

This is the format of the code: 1. 4 Digit Identifier of Store eg. ABCD 2. Type or Category of item purchased. eg. E for electronics, T for toys 3. Special secret two digit code eg. can be between 01 and 10. 4. Date in really short format. eg. 31J16 for 31st January, 2016 5. Four digit code for customers to use for support issues or returning an item. eg. 3267. This is randomly generated.

So a sample would look like this: ABCDT0131J163267 Total length is 16 characters.

Now what I want to do is each time a code is generated make sure it does not already exist in my database if yes then it should generate a new one and so on till it comes up with a unique code.

Now my issue is getting an efficient solution t generate unique codes that won't end up looping soo many times like I intend on doing.



via Chebli Mohamed

Best way to manage laravel 5 logs for each event

I wants to logs for each events happened in my website. I would like to know what will be the best way to handle this?

I looked at the packages available but it's not in my requirement.

Let say I wants to record every email activity went through the system plus all insert/update/delete performed by the system user.

I saw EventListener but each time I have to fire an event from the controller I would love if is there any way if I just have to write one time code at somewhere so anytime insert/update/delete happened It will be recorded yes plus emails as well.

Help would be most appreciated.

Thank you.



via Chebli Mohamed

Laravel5.1 Logout when browser is close using javascript

How to detect that browser is close using javascript. I have not found any solutions using laravel. So now I am using jquery ajax request to logout before window is close. For this I am using-

function windowUnloaded() {

    var unloaded = false;
    $(window).on('beforeunload', unload);
    function unload(){      
        if(!unloaded){
            $('body').css('cursor','wait');
            $.ajax({
                type: 'get',
                async: false,
                url: '/logout',
                success:function(){ 
                    unloaded = true; 
                    $('body').css('cursor','default');
                },
                timeout: 5000
            });
        }
    }
}

This works only when I refresh page. But I want it when browser is close. Somebody can tell me from where I am wrong or If there is any other better solution. Thanks in advance.



via Chebli Mohamed

Laravel about Requests

i am new in programing laravel. so here I will not ask about my problems but I am here just want to ask how to use laravel. here I would like to ask how to use:

Determining If an Input Value Is Present in laravel. and what it does?

thanks ^^



via Chebli Mohamed

adding data to @include throws an error

My head is aching as to what is the error in my code.

main.blade.php

Html with angular codes here....
@include('modal-template-common', ['link' => route('client.logout')]

modal-template-common.blade.php

{!! Html::link($link, 'OK', ('class'=>'btn btn-danger')) !!}

Now the problems is whenever I try to render it returns an error of

ErrorException in UrlGenerator.php line 273

angular.js:11607 Error: [$compile:tpload]

any enlightenment would greatly help me.



via Chebli Mohamed