如果登录,我想将用户重定向到主页,并希望访问登录/注册页面,如果未登录,我想将用户重定向到登录页面并希望访问其他页面。有些页面被排除在外,这意味着不需要登录,所以我的代码就在下面:
router.beforeEach((to, from, next) => {
if(
to.name == 'About' ||
to.name == 'ContactUs' ||
to.name == 'Terms'
)
{
next();
}
else
{
axios.get('/already-loggedin')
.then(response => {
// response.data is true or false
if(response.data)
{
if(to.name == 'Login' || to.name == 'Register')
{
next({name: 'Home'});
}
else
{
next();
}
}
else
{
next({name: 'Login'});
}
})
.catch(error => {
// console.log(error);
});
}
});
Run Code Online (Sandbox Code Playgroud)
但问题是它进入了一个无限循环,例如每次登录页面加载而用户未登录时,它会将用户重定向到登录页面,然后再次重定向到登录页面,然后......
我怎样才能解决这个问题?
我正在使用 Laravel,当我将项目上传到服务器时,它返回 500、503 和其他类型的错误。因为我正在使用,Virtualmin所以我检查了 error_log /var/log/virtualmin,发现它php-fpm没有启用。所以我启用了它,现在所有页面上都出现File not found错误!
所以我添加ProxyErrorOverride on到文件中/etc/httpd/conf/httpd.conf,但后来Not Found
The requested URL /index.php was not found on this server.我对其进行了评论并添加<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>,但它再次返回File not found。
然后我进入/etc/php-fpm.d/www.conf并编辑了这部分从;chroot =到chroot = /home/mysite/public_html/public。但没有结果:(
更新
我的根文件夹中没有任何.htaccess文件,但在公共文件夹中,并且在其中我有:
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If …Run Code Online (Sandbox Code Playgroud) 我正在使用 WooCommerce,并且想要获取专门针对该产品的元密钥,例如价格、颜色等...但问题是我不想获取所有元密钥,而只想获取所需的元密钥。例如,我不需要_edit_last, _edit_lock, _wc_review_count... 而只需要priceand color(作为示例)。如果它是一个不重要的网页,但我不想在网页上显示它们,但我想将它们作为 json 发送到其他地方。所以应该对数据进行过滤。顺便说一句,它在插件中,我想与其他人分享,所以我不能/不应该访问他们的 WooCommerce api。
我的代码获取所有元键(但我只想要其中的一些):
$attributes = get_post_meta($product->get_id());
foreach($attributes as $key => $value) {
$result['products'][$p]['attributes'][$key] = $value[0];
}
Run Code Online (Sandbox Code Playgroud)
上面代码的结果是:
[attributes] => Array
(
[_edit_last] => 1
[_edit_lock] => 1594817821:1
.
.
.
)
Run Code Online (Sandbox Code Playgroud)
但我想要:
[attributes] => Array
(
[price] => 1000
[color] => 'red'
.
.
.
)
Run Code Online (Sandbox Code Playgroud) 由于安全原因,我将所有目录和文件移动到一个主目录中,并将所有文件/目录从公共文件夹中取出到 Laravel 项目的根目录。现在我想将npm run devscss 文件编译为 css,将 js 编译为 js。但是,每次我运行npm run dev它时,它都会public在我创建的主文件夹中创建一个名为的文件夹,并将编译后的文件放入其中。但我想把它放在根文件夹中,其中包含:css-js-svg-fonts-index 所以我改变了
这个:
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
Run Code Online (Sandbox Code Playgroud)
对此:
mix.js('resources/js/app.js', '../../js')
.sass('resources/sass/app.scss', '../../css');
Run Code Online (Sandbox Code Playgroud)
但没有结果:(它只是在主文件夹中创建公用文件夹,这不是我希望它上一级的根目录。
谢谢
我应该将该列更改deleted为1将其视为已删除,还是最好将记录移至另一个表?
标志方法很好,因为后面的选择将搜索更少的记录。第二种方法有点复杂,不是吗?
哪种方法更好?
我想使用以下代码:Model::update($request);,但是表中的所有字段都可能被恶意用户修改,因此我更改$fillable模型中的 以仅修改用户可以修改的字段,而不能修改其他字段。但是现在的问题是我不能通过自己的价值观来修改它。
id name verified
1 Alex 0
Run Code Online (Sandbox Code Playgroud)
如果恶意用户发送的数据$request是:
[
'name' => 'ModifiedAlex',
'verified' => 1,
]
Run Code Online (Sandbox Code Playgroud)
所以它会修改表并得到验证是不好的当设置$fillable为仅名称时:
$fillable = [
'name'
];
Run Code Online (Sandbox Code Playgroud)
那么我自己就不能用Model::where('id', $userId)->update(['verified' => 1]).
那该怎么办呢?使用$fillable与否?
我的代码:
$data['from'] = '2020-03-20 20:30:00';
$data['to'] = '2020-03-21 00:45:00';
$validity = \Validator::make($data, [
'from' => ['date_format:Y-m-d H:i:s'],
'to' => ['date_format:Y-m-d H:i:s']
]);
// This if gets true, and the error message is:
Run Code Online (Sandbox Code Playgroud)
to 与格式 Ymd H:i:s 不匹配
if($validity->fails()) {
dd($validity->errors());
}
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,当我改变它时00:45:00,01:45:00它并没有进入如果。我该如何解决?
我正在制作一个 chrome 扩展,其中有一个 iframe。当扩展程序请求服务器以获取页面时,它会返回错误Refused to display 'https://subdomain.example.com/' in a frame because it set 'X-Frame-Options' to 'deny'。尽管我已在我的文件中设置了x-frame-optionsto并在后端项目的特定方法中添加了 a ,但它返回了另一个错误。我在我的文件中添加了和。不走运,它返回了,所以我删除了权限并添加了v3 的权限。没有结果!!然后我添加了deny.htaccessheader('x-frame-options: GOFORIT')Refused to display 'https://subdomain.example.com/' in a frame because it set multiple 'X-Frame-Options' headers with conflicting values ('GOFORIT, DENY'). Falling back to 'deny'webRequestwebRequestBlockingpermissionsmanifest.json'webRequestBlocking' requires manifest version of 2 or lowerUnchecked runtime.lastError: You do not have permission to use blocking webRequest listeners. Be sure to declare the webRequestBlocking permission …
javascript google-chrome google-chrome-extension x-frame-options chrome-extension-manifest-v3
const url = new URLSearchParams('https://example.com?q1=1&q2=2');
console.log(url.has('q3')) // returns false as expected
console.log(url.has('q2')) // returns true as expected
console.log(url.has('q1')) // returns false as NOT expectedRun Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?
<input type="file" accept=".jpg">
Run Code Online (Sandbox Code Playgroud)
这使文件选择对话框默认为仅允许JPG文件,但是还有一个下拉菜单用于选择所有文件:All Files (*.*)。我如何才能使其仅允许JPG文件,而不能在下拉菜单中选择“所有文件”?
laravel ×4
php ×4
javascript ×2
apache ×1
chrome-extension-manifest-v3 ×1
datetime ×1
delete-row ×1
html ×1
laravel-mix ×1
metadata ×1
product ×1
query-string ×1
sql ×1
vue-router ×1
vue.js ×1
webpack ×1
woocommerce ×1
wordpress ×1