php

PHP实现大转盘抽奖算法

耗尽温柔 提交于 2021-02-18 11:49:58
流程: 1.拼装奖项数组,2.计算概率,3.返回中奖情况 代码如下:中奖概率 ' v ' 可以在后台设置,传到此方法中,注意传整数 function get_gift(){ // 拼装奖项数组 // 奖项id,奖品,概率 $prize_arr = array ( '0' => array ('id'=>1,'prize'=>'平板电脑','v'=>0), '1' => array ('id'=>2,'prize'=>'数码相机','v'=>0), '2' => array ('id'=>3,'prize'=>'音箱设备','v'=>0), '3' => array ('id'=>4,'prize'=>'4G优盘','v'=>5), '4' => array ('id'=>5,'prize'=>'10Q币','v'=>0), '5' => array ('id'=>6,'prize'=>'空奖','v'=>5), ); foreach ( $prize_arr as $key => $val ) { $arr [ $val ['id']] = $val ['v']; // 概率数组 } $rid = $this ->get_rand( $arr ); // 根据概率获取奖项id $res ['yes'] = $prize_arr [ $rid -1]['prize']; // 中奖项

Laravel - Include assets on Middleware Auth

会有一股神秘感。 提交于 2021-02-18 11:47:46
问题 Inside my app, exist a route group called admin , any route inside this group call two resources: public/css/admin.css and public/js/admin.js , but any unauthenticated user has access to these files. How can I include these files inside the Auth Middleware? My admin routes: Route::group(['prefix' => 'admin', 'middleware' => ['auth']], function () { Route::get('/', 'Admin\IndexController@index')->name('panel'); Route::group(['prefix' => 'users'], function() {}); Route::group(['prefix' =>

Why do server-sent events initiate every 3 seconds? [duplicate]

半城伤御伤魂 提交于 2021-02-18 11:46:26
问题 This question already has answers here : Setting time interval in HTML5 server sent events (4 answers) Closed 2 years ago . I am new to server-sent events, so I am trying this W3Schools example on WAMP Server. The files I have are: demo_sse.php <?php header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); $time = date('r'); echo "data: The server time is: {$time}\n\n"; flush(); ?> index.php <!DOCTYPE html> <html> <body> <h1>Getting server updates</h1> <div id="result"><

Yii2 remove index.php from url

纵然是瞬间 提交于 2021-02-18 11:20:48
问题 When I set the option in Yii to remove index.php from the URL I get a 404 error and this error in the error logs File does not exist: /var/live/var . In my browser I get this error The requested URL /var/decat/frontend/web/index.php was not found on this server. but the file is exactly in that location. What might explain that is that my document root is /var/live and decat is an alias as shown in the conf file. This url works fine http://13.21.16.180/decat/index.php/site/login but when I

How to use 'where' on column with comma separated values in laravel

倖福魔咒の 提交于 2021-02-18 11:20:07
问题 I am using php with laravel framework. I want to get rows from table that contains user id. Problem here is that user id is integer value and column(author) contain more than one comma separated integer values. Here is example. DB::table('stories')->where('author','4')->get(); author column have values : row 1: 2,4,5 | row 2: 1,3,14 | row 3 : 4,5 and I will get row 1 and 3. So, Please help me to get right rows. 回答1: You can use whereRaw like as DB::table('stories')->whereRaw("find_in_set('4'

Avoid percent-encoding href attributes when using PHP's DOMDocument

走远了吗. 提交于 2021-02-18 11:11:29
问题 The best answers I was able to find for this issue are using XSLT, but I'm just not sure how to apply those answers to my problem. Basically, DOMDocument is doing a fine job of escaping URLs (in href attributes) that are passed in, but I'm actually using it to build a Twig/Django style template, and I'd rather it leave them alone. Here's a specific example, illustrating the "problem": <?php $doc = new DOMDocument(); $doc->loadHTML('<html><body>Test<br><a href="{{variable}}"></a></body></html>

MySQLi get_result() undefined when mysqlnd is installed

*爱你&永不变心* 提交于 2021-02-18 11:11:22
问题 I am writing a simple test script to get my head around MySQLi prepared statements. This script will become the basis for a function that needs to be slightly dynamic in its handling of results. I need the fetch method to return as an array similar to how mysql_fetch_array() behaves. I am aware some of these methods require mysqlnd. I have checked phpinfo. Mysqlnd is installed and present. See screenshot. Please note, PDO is available on my server, but I need to get this script working with

MySQLi get_result() undefined when mysqlnd is installed

三世轮回 提交于 2021-02-18 11:05:31
问题 I am writing a simple test script to get my head around MySQLi prepared statements. This script will become the basis for a function that needs to be slightly dynamic in its handling of results. I need the fetch method to return as an array similar to how mysql_fetch_array() behaves. I am aware some of these methods require mysqlnd. I have checked phpinfo. Mysqlnd is installed and present. See screenshot. Please note, PDO is available on my server, but I need to get this script working with

mysqli_multi_query - Commands out of sync; you can't run this command now

允我心安 提交于 2021-02-18 10:56:47
问题 I have several query strings which I want to execute at once using "mysqli_multi_query". This works. When I insert a query again to check each item in joined tables using "mysqli_query" it doesn't return any result nor any error from PHP. When I run the query string manually in phpmyadmin, everything works fine as it should. Here's my code: <?php $connect = mysqli_connect('localhost','root','','database'); $strquery = ""; $strquery .= "1st Query"; $strquyer .= "2nd Query"; if($multi = mysqli

Mysql count rows using filters on high traffic database

情到浓时终转凉″ 提交于 2021-02-18 10:49:06
问题 Let's say you have a search form, with multiple select fields, let's say a user selects from a dropdown an option, but before he submits the data I need to display the count of the rows in the database . So let's say the site has at least 300k(300.000) visitors a day, and a user selects options from the form at least 40 times a visit, that would mean 12M ajax requests + 12M count queries on the database, which seems a bit too much . The question is how can one implement a fast count (using