小编Pra*_*eep的帖子

PHP:使用exit(); 或者死(); 标题后("位置:");

我有一个简单使用的用户登录/注册系统

// execute queries, set cookies, etc. here
header("Location: " . getenv("HTTP_REFERER"));
Run Code Online (Sandbox Code Playgroud)

我最近阅读了一篇关于exit();并且die();不知道我应该使用这些内容的帖子.根据我的理解,他们让它结束PHP?那是对的吗?我能为此努力的最佳方法是什么,只需在header()之后直接添加其中一个函数; 执行我有吗?

我有AJAX,通过我的login.php/register.php阅读jQuery,这会以任何方式影响吗?

编辑:除了header();之后,我应该在哪里使用exit();或者die();函数?并且exit();更多地用于PHP,而die();更多用于Perl?

php exit die

17
推荐指数
2
解决办法
2万
查看次数

使用Mojo :: DOM时NBSP格式错误

我正在使用Mojo :: DOM Perl模块替换<IMG>标签,但&nbsp;实体被Mojo :: DOM替换为\ xa0,但是当我将其打印到页面时,NBSP字符变为\ x {fffd}并显示为问号.我尝试过更换\n  但这样做会破坏另一个unicode角色.这是我的代码:

#!/usr/bin/perl

use utf8;
use strict;
use warnings;
use CGI;

my $cgi = new CGI;

print $cgi->header(-charset => 'utf-8');

my %params = $cgi->Vars;

print q[<html><head><title>UTF-8 Test</title></head><body><form method="POST"><textarea name="msg" cols="50" rows="20">].$params{msg}.q[</textarea><br/><br/><input type="submit"></form>];

if($ENV{REQUEST_METHOD} eq 'POST') {
    require Mojo::DOM;


    my $dom = Mojo::DOM->new($params{msg});

    for my $e ($dom->find('img')->each) {
          my $x = $e->attr('data-char');

          if(defined($x) && $x) {
             $e->replace($x);
          }
          else {
              $e->delete;
          }
    }

    $params{msg} = $dom->to_string();
    print '<hr/><div>'.$params{msg}.'</div>';
} …
Run Code Online (Sandbox Code Playgroud)

unicode perl html-entities mojolicious

9
推荐指数
1
解决办法
179
查看次数

如何使用 Mojo::Useragent 放置文件?

我正在尝试使用 PUT 方法使用 Mojo::UserAgent 上传文件,文件可能很大,而不是将文件内容作为标量传递,还有其他方法吗?

这是我尝试过的:

use strict;
use warnings;
use Mojo::UserAgent;
use Mojo::Asset::File;


my $ua = Mojo::UserAgent->new;

my $file = $ARGV[0];

die("File not found") unless(-f $file);

my $a_file = Mojo::Asset::File->new(path => $file);

my $tx = $ua->put('https://postman-echo.com/put' => {'X-Test' => '123G'} => $a_file);

print $tx->success;

print "\n\n";

print $tx->result->body;

print "\n\n";

print $tx->req->text;
Run Code Online (Sandbox Code Playgroud)

perl http-put mojolicious mojo-useragent

5
推荐指数
1
解决办法
282
查看次数

将数组传递给Perl长度子例程时会发生什么?

这是我的代码:

my @list = qw (The quick brown fox jumps over the lazy Perl programmer); 
my @list1 = qw (Sparta F R I j h df dfsd dfsdf ); 
my @list2 = qw (The quick brown fox jumps over the lazy Perl programmer); 
print length(@list), "\n"; 
print length(@list1), "\n"; 
print length(@list2), "\n";
Run Code Online (Sandbox Code Playgroud)

我得到的输出:

2
1
2
Run Code Online (Sandbox Code Playgroud)

输出背后的原因是什么?它不应该给我第一个元素的长度吗?

perl string-length subroutine

2
推荐指数
2
解决办法
68
查看次数

Issue with goto statement along with if else condition

我正在尝试为平等检查和转到标签概念创建一个简单的 perl 分配。
用户输入数字,进行相等检查,询问用户是否要检查更多,如果是,则重复,否则退出。对此
问题使用“goto” - y/n 检查是否重复,y 用于重复标签。即使我输入“n”,它也会继续转到标签 Loop 。为什么包含“goto”的“if”条件没有得到尊重?下面的代码

#Checking Equality

Loop: print "\Checking Equality\n";
print "Enter number for variable a\n";
$a = <stdin>;
print "Enter number for variable b\n";
$b = <stdin>;
if ( $a == $b ) {
    print 'a and b are equal';
    print "\n\n";
}
else {
    print 'a and b are not equal';
}
print "\n\n";
print "do you want to check more? Enter y/n\n";
$c = <stdin>;
if ( $c == "y" …
Run Code Online (Sandbox Code Playgroud)

perl

1
推荐指数
1
解决办法
83
查看次数