我正在尝试将我的phpmyadmin目录限制为仅允许我的IP从家中使用.这是一个不在我的网络上的远程VPS:
location ^~ /9ZXyNSDVTM7yExN/ { #this is the phpmyadmin directory (I renamed it)
allow 127.10.176.5; #This is my IP
deny all;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我进入页面时,它给我一个404错误.奇怪的是,如果我将上面代码中的IP更改为不是我的随机IP,则会发出403 Forbidden错误而不是404错误.
如果删除整个位置块,我不会收到404错误.为什么这个限制块不起作用?
另外,这是我的整个nginx.conf:
#user html;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on; …Run Code Online (Sandbox Code Playgroud) 您好,我正在尝试在我的网站上使用 cookie。在我的网站中实现它们之前,我创建了两个测试页面来尝试它们,但它似乎效果不佳。
第一页有:
<?php
setcookie("apple", "abc", time()+1500, "/", "b****a.org");
?>
Run Code Online (Sandbox Code Playgroud)
第二页有:
<?php
echo $_COOKIE["apple"];
?>
Run Code Online (Sandbox Code Playgroud)
因此,为了测试它,我首先转到第一页,然后转到第二页。由于某种原因,第二页只在屏幕上输出字母“b”。就是这样。我在另一台电脑上试了一下,它输出“abcb”,这个b是做什么用的?我猜 cookie 没有存储在我的计算机上,但它确实可以在另外两台计算机上工作,所以我猜这只是我的问题。无论如何,为什么它最后会输出一个额外的“b”?
谢谢。
我试图从两个不同的文本文件中获取两个不同的数字,将它们放入一个变量中,并将其与MYSQL数组进行比较.我的问题是当我定义三个变量时:
$num = 42;
$whichPlaylist = 2;
$joint = "$whichPlaylist $num"
Run Code Online (Sandbox Code Playgroud)
并使用数组进行测试,它的工作原理.但是,如果我从文本文件中取出2和42,它就不起作用.我尝试过使用$ trim,但似乎没有解决它.为什么当我定义我的变量时它才起作用,但是当我从文本文件中获取变量时它不起作用?它们具有完全相同的东西(文本文件虽然有新行).
这是我的代码:
//Connect to DB
$config = array(
'host' => 'localhost',
'username' => '******',
'password' => '******',
'dbname' => '******'
);
$db = new PDO('mysql:host='.$config['host'].';dbname='.$config['dbname'],$config['username'],$config['password']);
$query = $db->query("SELECT `recentlyplayed`.`numplayed`, `recentlyplayed`.`id` FROM `recentlyplayed`");
//Put numbers from text files into variables
$num = file_get_contents('/home/*****/num.txt'); // has the value "42" with new line
$whichPlaylist = file_get_contents('/home/*****/whichplaylist.txt'); // has the value "2" with newline
$playlist3_num = file_get_contents('/home/*****/playlist3_num.txt');
//$whichPlaylist = 2;
//$num = …Run Code Online (Sandbox Code Playgroud) 我已经尝试过阅读一些不同的教程,但我仍然无法弄明白.我有两个简单的课程.动物和猫.
class Animal:
def __init__(self, name):
self.name = name
class Cat(Animal):
def __init___(self, age):
self.age = age
print('age is: {0}'.format(self.age))
def talk(self):
print('Meowwww!')
c = Cat('Molly')
c.talk()
Run Code Online (Sandbox Code Playgroud)
输出是:
Meowwww!
Run Code Online (Sandbox Code Playgroud)
代码运行,但我有点困惑.我创建了一个cat类的实例c = Cat('Molly').因此,不知何故,通过使用"Molly"作为Cat()类实例的参数,它将提供"Molly"给原始基类(Animal)而不是Cat我创建的类实例?为什么?那么如何为Cat类实例提供age它需要的变量呢?
我试过做:
c = Cat('Molly', 10)
Run Code Online (Sandbox Code Playgroud)
但它抱怨太多的争论.其次,为什么不会__init__调用Cat类的功能?它应该打印"年龄是......".它永远不会.
编辑:得到它的工作,感谢Martijn Pieters!这是更新的代码(适用于python3):
class Animal():
def __init__(self, name):
self.name = name
print('name is: {0}'.format(self.name))
class Cat(Animal):
def __init__(self, name, age):
super().__init__(name)
self.age = age …Run Code Online (Sandbox Code Playgroud)