I have a PHP project in which I have an index.html with a simple form:
<p>Test connection</p>
<form action="Servicios.php" method="post">
<input type='submit' name='Test' value='Test'>
</form>
in Servicios.php Im trying to process it like this
<?php
echo "can you print this";
if($_SERVER["REQUEST_METHOD"]=="POST" )
{
if(!empty($_POST["Test"]))
{
echo "Hello world";
}
}
But it doesn't works, thats because it never evaluates the first if like "true". The first echo at the top does works but if I do an echo to $_SERVER["REQUEST_METHOD"] it doesn't give me anything. I've tried with isset($_POST['Hola']) but I had the same result.
This only happens in the project I have in an internet host. I wrote this exact same code in my local computer using netbeans and xampp and it works perfectly. I have no idea why.
I have the feeling that I'm making some silly mistake but I cant find it.
My host is an Ubuntu server from the ec2 Amazon Web Services.
Edit
this is the output of <?=print_r($_SERVER);?> in Servicios.php
I replaced the parts where my ip is showed with [ip]
Array (
[HTTP_HOST] => [ip]
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => es-MX,es-ES;q=0.9,es;q=0.7,es-AR;q=0.6,es-CL;q=0.4,en-US;q=0.3,en;q=0.1
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_REFERER] => http://[ip]/ProyectoPM/
[CONTENT_TYPE] => application/x-www-form-urlencoded
[CONTENT_LENGTH] => 11
[HTTP_CONNECTION] => keep-alive
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[SERVER_SIGNATURE] => Apache/2.4.18 (Ubuntu) Server at [ip] Port 80
[SERVER_SOFTWARE] => Apache/2.4.18 (Ubuntu)
[SERVER_NAME] => [ip]
[SERVER_ADDR] => 172.31.43.105
[SERVER_PORT] => 80
[REMOTE_ADDR] => 189.208.87.127
[DOCUMENT_ROOT] => /var/www/html
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /var/www/html
[SERVER_ADMIN] => webmaster#localhost
[SCRIPT_FILENAME] => /var/www/html/ProyectoPM/Servicios.php
[REMOTE_PORT] => 5672
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[REQUEST_URI] => /ProyectoPM/Servicios.php
[SCRIPT_NAME] => /ProyectoPM/Servicios.php
[PHP_SELF] => /ProyectoPM/Servicios.php
[REQUEST_TIME_FLOAT] => 1510846404.812
[REQUEST_TIME] => 1510846404 ) 1
This is in the array it returns with <?=var_dump($_SERVER); ?>
["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1"
["REQUEST_METHOD"]=> string(4) "POST"
["QUERY_STRING"]=> string(0) ""
["REQUEST_URI"]=> string(25) "/ProyectoPM/Servicios.php"
["SCRIPT_NAME"]=> string(25) "/ProyectoPM/Servicios.php"
["PHP_SELF"]=> string(25) "/ProyectoPM/Servicios.php"
["REQUEST_TIME_FLOAT"]=> float(1510847672.582)
["REQUEST_TIME"]=> int(1510847672) }
A more important edit
At first I said that a simple echo "can you print this"; worked in the host, now I see that it doesn't either. When I move to Servicios.php in by clicking my button in index.html the browser moves to Servicios.php (it displays it in the url) but it simply doesnt show anything. It only shows something if i delete all the code an put a instrucion like <?=print_r($_SERVER);?> which result I already put above.
if(isset($_POST['Test'])){
echo 'Hello world';
}
This should work. This is checking is button is submitted using POST method. This should be enough check to see if form has been submitted.
You can try this to check if post method
if(strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
// if form submitted with post method
// validate request,
// manage post request differently,
// log or don't log request,
// redirect to avoid resubmition on F5 etc
}
Related
How do I get, from which page/url the data in the $_POST variable come from :$_SERVER['HTTP_HOST'] ?
You must use
$_SERVER['HTTP_REFERER']
The super-global $_SERVER could be useful for you, specifically $_SERVER['REQUEST_URI']:
echo '<pre>';
print_r($_SERVER);
// [DOCUMENT_ROOT] =>
// [REMOTE_ADDR] =>
// [REMOTE_PORT] =>
// [SERVER_SOFTWARE] =>
// [SERVER_PROTOCOL] =>
// [SERVER_NAME] =>
// [SERVER_PORT] =>
// [REQUEST_URI] => /f1 <-----------------
// ...
I'm trying to make one page control all incoming requests. [Is that a good choice?]
This feature bans bruteforcing of directories and files with, say, DirBuster.
My website's public_html looks like this:
data/
<files and libraries>
.htaccess
index.php
.htaccess
The data/.htaccess file only contains Deny from all.
What is the query for /.htaccess to redirect everything after first slash
website.com/query?a=b&c=d
to
website.com/index.php?resolve=query%3Fa%3Db%26c%3Dd
To use like this:
[index.php]
<?php
if(isset($_GET["resolve"])){
$URL = $_GET["resolve"];
require("data/resolve.php");
exit;
}
?>
[data/resolve.php]
<?php
echo "Resolving " . $URL;
?>
UPDATE
I'm using this rule:
RewriteEngine on
RewriteRule ^(.*)$ index.php?u=$1 [NC,QSA]
And this is the dump of $_SERVER:
Array
(
[REDIRECT_UNIQUE_ID] => WPNBPFfUF3-ZHr123R9sKVVAAAAAY
[REDIRECT_PHP_DOCUMENT_ROOT] => /storage/h1231/8412316/1388846/public_html
[REDIRECT_DOCUMENT_ROOT] => /storage/h2134/846/138123231846/public_html
[REDIRECT_SERVER_ADMIN] => webmaster#000webhost.io
[REDIRECT_STATUS] => 200
[UNIQUE_ID] => WPNBPFfUF3-ZHrCR123KVVAAAAAY
[PHP_DOCUMENT_ROOT] => /storage/h14/84123/1238846/public_html
[DOCUMENT_ROOT] => /storage/h14/846/1312346/public_html
[SERVER_ADMIN] => webmaster#000webhost.io
[HTTP_CONNECTION] => Keep-Alive
[HTTP_PROXY_CONNECTION] => Keep-Alive
[HTTP_HOST] => fanfiction-app.ml
[HTTP_X_FORWARDED_PROTO] => http
[HTTP_X_REAL_IP] => RE.DA.CT.ED
[HTTP_X_FORWARDED_FOR] => RE.DA.CT.ED
[HTTP_X_DOCUMENT_ROOT] => /storage/h123/1236/11236/public_html
[HTTP_X_OPEN_BASEDIR] => /opt/awex-pages:/storage/h14/846/1388846
[HTTP_X_UPSTREAM] => php71_7
[HTTP_X_SERVER_ADMIN] => webmaster#000webhost.io
[HTTP_X_SERVER_NAME] => website.com
[HTTP_X_AWEX_UID] => 13236
[HTTP_X_TEMP_DIR] => /storage/h14/846/1123123/tmp
[HTTP_WE_ARE_HIRING] => 1492336956.980
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp;q=0.8
[HTTP_DNT] => 1
[HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,ru;q=0.6
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[SERVER_NAME] => website.com
[SERVER_ADDR] => 2202:3380:bad:7::126
[SERVER_PORT] => 80
[REMOTE_ADDR] => RE.DA.CT.ED
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /storage/h14/836/1312346/public_html
[SCRIPT_FILENAME] => /storage/h13/846/138123846/public_html/index.php
[REMOTE_PORT] => 34141
[REDIRECT_QUERY_STRING] => resolve=query.php&a=b
[REDIRECT_URL] => /query.php
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => resolve=index.php&resolve=query.php&a=b
[REQUEST_URI] => /query.php?a=b
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1492336956.981
[REQUEST_TIME] => 1492336956
)
When getting website.com/query?a=b, however the output of $_GET["resolve"] is query.php.
Add this to .htaccess file as the first lines.
RewriteEngine On
RewriteRule ^(.*)$ index.php?resolve=$1 [QSA]
Where $1 matches query?a=b&c=d
I haven't found a pure Apache .htaccess solution, but I'm going to accept my own answer since I made a PHP hack that seems to be working.
To achieve such functionality, redirect all traffic to one page. In my situation, it's index.php.
[.htaccess]
RewriteEngine on
RewriteRule ^(.*)$ index.php?resolve=$1 [NC,QSA]
[index.php]
<?php
if(isset($_GET["resolve"]) && $_GET["resolve"] != "") {
$URL = $_SERVER["REQUEST_URI"];
$GET = $_GET;
require "system/resolve.php";
exit;
}
echo "<pre>";
echo "Requested /";
echo "</pre>";
?>
[system/resolve.php]
<?php
/**
* $URL: Full URL query after the slash.
* $GET: All get parameters of the query.
*/
switch($_GET["resolve"]){
case "ping":
require "system/ping.php";
exit;
case "auth":
require "system/auth.php";
exit;
}
?>
In result, when you request http://example.com/ping, you will see a page from system/ping.php
I am new to PHP and got confused, I wrote a PHP script to log the server environment variables when user make request, and my code looks like this:
<?php
$req_dump = print_r($_SERVER, TRUE);
$fp = fopen('/tmp/request.log', 'a');
fwrite($fp, $req_dump);
fclose($fp);
echo "hello world";
However, the output looks like below:
Array
(
[HTTP_USER_AGENT] => anaconda/13.21.195
[HTTP_HOST] => 10.0.188.97
[HTTP_ACCEPT] => */*
[HTTP_X_ANACONDA_ARCHITECTURE] => x86_64
[HTTP_X_ANACONDA_SYSTEM_RELEASE] => Red Hat Enterprise Linux
[HTTP_X_RHN_PROVISIONING_MAC_0] => eth0 B4:99:BA:07:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_1] => eth1 B4:99:BA:07:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_2] => eth2 B4:99:BA:07:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_3] => eth3 B4:99:BA:07:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_4] => eth4 00:02:C9:4F:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_5] => eth5 00:02:C9:4F:xx:xx
[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
[SERVER_SIGNATURE] => <address>Apache/2.2.15 (Red Hat) Server at 10.0.188.97 Port 80</address>
[SERVER_SOFTWARE] => Apache/2.2.15 (Red Hat)
[SERVER_NAME] => 10.0.188.97
[SERVER_ADDR] => 10.0.188.97
[SERVER_PORT] => 80
[REMOTE_ADDR] => 10.0.188.212
[DOCUMENT_ROOT] => /var/www/html
[SERVER_ADMIN] => root#localhost
[SCRIPT_FILENAME] => /var/www/html/ks.php
[REMOTE_PORT] => 59188
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /ks.php/images/install.img
[SCRIPT_NAME] => /ks.php
[PATH_INFO] => /images/install.img
[PATH_TRANSLATED] => /var/www/html/images/install.img
[PHP_SELF] => /ks.php/images/install.img
[REQUEST_TIME] => 1402439673
)
How I tried to access the array:
FYI, here is the code how I tried to access that array:
# ks.php
<?php
$Table = array(
"00:02:C9:10:aa:bb" => "10.0.188.91",
"00:02:C9:4F:aa:bb" => "10.0.188.92",
"00:02:C9:53:aa:bb" => "10.0.188.93",
"00:02:C9:56:aa:bb" => "10.0.188.94",
"00:02:C9:53:aa:bb" => "10.0.188.95",
"00:02:C9:4E:aa:bb" => "10.0.188.96",
"00:02:C9:5A:aa:bb" => "10.0.188.97",
);
?>
...
%post
...
printf 'DEVICE=eth4 \nIPADDR=<?php echo $Table[$_SERVER["HTTP_X_RHN_PROVISIONING_MAC_4"]]; ?>' > /etc/sysconfig/network-scripts/ifcfg-eth4
service network restart
...
%end
The output doesn't look like straight forward to me. Say I want to get the MAC address of ethernet4, and $_SERVER["HTTP_X_RHN_PROVISIONING_MAC_4"] doesn't work for me.
Can anyone help me explain how to achieve that in PHP?
your $_SERVER['HTTP_X_RHN_PROVISIONING_MAC_4'] output is eth4 00:02:C9:4F:xx:xx which also has a prefix eth4 where as your $Table has 00:02:C9:4F:aa:bb which makes the keys mismatch and actually you are trying to get $Table['eth4 00:02:C9:4F:xx:xx'] which is non existent in your $Table array
Try this:
// We are splitting the mac address by space so that $macAddress contains '00:02:C9:4F:xx:xx' and $eth contains eth4
list($eth,$macAddress) = explode(' ',$_SERVER['HTTP_X_RHN_PROVISIONING_MAC_4']);
// Make sure the value in $macAddress => 00:02:C9:4F:xx:xx is 00:02:C9:4F:aa:bb or change your array accordingly
$Table = array(
"00:02:C9:10:aa:bb" => "10.0.188.91",
"00:02:C9:4F:aa:bb" => "10.0.188.92",
"00:02:C9:53:aa:bb" => "10.0.188.93",
"00:02:C9:56:aa:bb" => "10.0.188.94",
"00:02:C9:53:aa:bb" => "10.0.188.95",
"00:02:C9:4E:aa:bb" => "10.0.188.96",
"00:02:C9:5A:aa:bb" => "10.0.188.97",
);
$finalAddress = $Table[$macAddress];
printf 'DEVICE=eth4 \nIPADDR=<?php echo $finalAddress ; ?>' > /etc/sysconfig/network-scripts/ifcfg-eth4 '
If you just save the array, it becomes like a useless print out. To make it accessible, use json_encode when you save it:
$fp = fopen('/tmp/request.log', 'w');
fwrite($fp, json_encode($_SERVER));
fclose($fp);
Note how I removed the print_r since it’s unnecessary for a task like this. I also changed fopen to overwrite the file using w instead of a so the saved JSON is valid.
Then when you open the file, just use json_decode like this:
$server_variables_json = file_get_contents('/tmp/request.log');
$server_variables = json_decode($server_variables_json , true);
Then $server_variables is an actual array you can act on like this:
if (array_key_exists('HTTP_X_RHN_PROVISIONING_MAC_4', $server_variables)) {
echo $server_variables['HTTP_X_RHN_PROVISIONING_MAC_4'];
}
The if (array_key_exists(…)) is something I put in place to help me debug this locally on my machine since I don’t have HTTP_X_RHN_PROVISIONING_MAC_4 set in my $_SERVER values.
A simple check I did locally to debug this—since I don’t have HTTP_X_RHN_PROVISIONING_MAC_4 in my setup—was just to get the HTTP_HOST like this:
if (array_key_exists('HTTP_HOST', $server_variables)) {
echo $server_variables['HTTP_HOST'];
}
If you want to put the var $_SERVER["HTTP_X_RHN_PROVISIONING_MAC_4"], don't forgot the quotes.
You need to use quotes to identify a non-numeric index:
echo $_SERVER['HTTP_X_RHN_PROVISIONING_MAC_4'];
You can get more basic information from the docs themselves.
Edit: I am not sure what you mean:
<?php
$array=array(
'HTTP_X_RHN_PROVISIONING_MAC_0' => 'eth0 B4:99:BA:07:xx:xx',
'HTTP_X_RHN_PROVISIONING_MAC_1' => 'eth1 B4:99:BA:07:xx:xx',
'HTTP_X_RHN_PROVISIONING_MAC_2' => 'eth2 B4:99:BA:07:xx:xx',
'HTTP_X_RHN_PROVISIONING_MAC_3' => 'eth3 B4:99:BA:07:xx:xx',
'HTTP_X_RHN_PROVISIONING_MAC_4' => 'eth4 00:02:C9:4F:xx:xx',
'HTTP_X_RHN_PROVISIONING_MAC_5' => 'eth5 00:02:C9:4F:xx:xx'
);
echo "Printing just a single element.\r\n";
echo $array['HTTP_X_RHN_PROVISIONING_MAC_4'];
echo "Printing the whole variable:\r\n";
print_r($array);
?>
Outputs the following:
Printing just a single element.
eth4 00:02:C9:4F:xx:xx
Printing the whole variable:
Array
(
[HTTP_X_RHN_PROVISIONING_MAC_0] => eth0 B4:99:BA:07:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_1] => eth1 B4:99:BA:07:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_2] => eth2 B4:99:BA:07:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_3] => eth3 B4:99:BA:07:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_4] => eth4 00:02:C9:4F:xx:xx
[HTTP_X_RHN_PROVISIONING_MAC_5] => eth5 00:02:C9:4F:xx:xx
)
Notice: Undefined index: HTTP_REFERER
$http_referer = $_SERVER['HTTP_REFERER']
i used this from tutorial.and it looks okay
also code is calling it from including file
what should i change?
i added print_r($_SERVER); and now page gives me this
Array ([UNIQUE_ID] => UoSxWa56310AAAwUckIAAAAA
[HTTP_HOST] => movafaghha.com
[HTTP_COOKIE] => __utma=210711305.58608218.1372977010.1372977010.1372977010.1; __utmz=210711305.1372977010.1.1.utmcsr=who.is|utmccn=(referral)|utmcmd=referral|utmcct=/whois/movafaghha.com; PHPSESSID=83eb0e2ae7ebe4b6c2eeb071d9f5de71
[HTTP_X_REAL_IP] => 109.109.41.81
[HTTP_X_FORWARDED_HOST] => movafaghha.com
[HTTP_X_FORWARDED_SERVER] => movafaghha.com
[HTTP_X_FORWARDED_FOR] => 109.109.41.81
[HTTP_CONNECTION] => close
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.48 Safari/537.36
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,fa;q=0.6
[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache
[SERVER_NAME] => movafaghha.com
[SERVER_ADDR] => 174.122.223.93
[SERVER_PORT] => 80
[REMOTE_ADDR] => 109.109.41.81
[DOCUMENT_ROOT] => /home/memarest/public_html/movafaghha.com
[SERVER_ADMIN] => webmaster#movafaghha.memarestan.com
[SCRIPT_FILENAME] => /home/memarest/public_html/movafaghha.com/tutorials/login200/register.php
[REMOTE_PORT] => 49737
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.0
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /tutorials/login200/register.php
[SCRIPT_NAME] => /tutorials/login200/register.php
[PHP_SELF] => /tutorials/login200/register.php
[REQUEST_TIME_FLOAT] => 1384427865.54
[REQUEST_TIME] => 1384427865
[argv] => Array ( )
[argc] => 0
)
edited the code but still unable to echo all fiedds are required
<?php
ini_set("display_errors", true);
error_reporting(E_ALL);
require 'core.inc.php';
if(!loggedIn()) {
//check mikunim ke tamame field ha dar form vojod darand va set shudan
if(isset($_POST['username'])&&isset($_POST['password'])&&isset($_POST['password_again'])&&isset($_POST['firstname'])&&isset($_POST['surename'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$password_again = $_POST['password_again'];
$firtsname = $_POST['firstname'];
$surename = $_POST['surename'];
//HALA CHECK MIKUNIM KHALI HASTAND YA NA
if(!empty($username)&&!empty($password)&&!empty($password_again)&&!empty($firstname)&&!empty($surename)){
echo 'ok' ;
} else {
echo ' All fields are required';
}
}
?>
<form action="register.php" method="POST">
Username:<br> <input type="text" name="username"><br> <br>
Password:<br> <input type="password" name="password"><br><br>
Password again:<br> <input type="password" name="password_again"><br><br>
Firstname:<br> <input type="text" name="firstname"><br><br>
Surname:<br> <input type="text" name="surename"><br><br>
<input type="submit" value="register">
</form>
<?php
} elseif (loggedIn()) {
echo 'you \'re already logged in';
}
?>
now after adding
"e"
page says "all fields are required"
but even when fill all fields message do not change
HTTP_REFERER is not guaranteed to be sent by the client:
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
In your case it's clearly not being sent, so really all you can do is
if(isset($_SERVER['HTTP_REFERER'])) {
//do what you need to do here if it's set
}
else
{
//it was not sent, perform your default actions here
}
if (isset($_SERVER['HTTP_REFERER'])) {$THE_REFER=$_SERVER['HTTP_REFERER']}
Undefined index means the array key is not set, do a:
var_dump($_POST); die();
before the line that throws the error and see that you're trying to get an array key that does not exist.
The Correct way to reffer is
$my_referer = isset($_POST['referer']) ? trim($_POST['referer']) : (isset($_SERVER['HTTP_REFERER']) ? base64_encode($_SERVER['HTTP_REFERER']) : false);
I'm trying to implement a PHP-based WebDAV server to be able to use it under OS Windows (more precisely Windows 7).
Everything works just fine, except for the PUT method. When I try to upload a file from the filesystem to the WebDAV server the request content-lenght is empty, meaning i can't read the file i want to put in the server.
Here is what I'm receiveng when I drag a file (simple .txt file) using Windows:
[HTTP_USER_AGENT] => Microsoft-WebDAV-MiniRedir/6.1.7601
[HTTP_TRANSLATE] => f
[CONTENT_LENGTH] => 0
[HTTP_VIA] => 1.1 squid.Sole:3128 (squid/2.7.STABLE9), 1.0 squidcache.Proxy6.CCSP:3129 (squid/2.6.STABLE24)
[PATH] => /bin:/usr/bin:/sbin:/usr/sbin
[SERVER_SOFTWARE] => Apache
[SERVER_PORT] => 80
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.0
[REQUEST_METHOD] => PUT
Uploading the same file using a dedicated webdav client, i get a valid response and the file is being uploaded. Here is what I get using CyberDuck client:
[HTTP_EXPECT] => 100-continue
[CONTENT_LENGTH] => 263
[CONTENT_TYPE] => text/plain
[HTTP_CONNECTION] => Keep-Alive
[HTTP_USER_AGENT] => Cyberduck/4.2.1 (9350) (Windows 7/6.1) (x86)
[HTTP_ACCEPT_ENCODING] => gzip,deflate
[PATH] => /bin:/usr/bin:/sbin:/usr/sbin
[SERVER_SOFTWARE] => Apache
[SERVER_PORT] => 80
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => PUT
The CONTENT-LENGTH field changed and the file is online on the server as i should be.
I will post my code fragment here:
$options = Array();
$options["path"] = $this->path;
$options["content_length"] = $_SERVER["CONTENT_LENGTH"];
$options["stream"] = fopen('php://input', 'r');
$stat = $this->PUT($options); // In the PUT method I fopen the destination file in "w"
if ($stat === false) {
$stat = "403 Forbidden";
} else if (is_resource($stat) && get_resource_type($stat) == "stream") {
$stream = $stat;
$stat = $options["new"] ? "201 Created" : "204 No Content";
if (!empty($options["ranges"])) {
if (0 == fseek($stream, $range[0]["start"], SEEK_SET)) {
$length = $range[0]["end"]-$range[0]["start"]+1;
if (!fwrite($stream, fread($options["stream"], $length))) {
$stat = "403 Forbidden";
}
} else {
$stat = "403 Forbidden";
}
}else {
while (!feof($options["stream"])) {
if (false === fwrite($stream, fread($options["stream"], 4096))) { //The fread reads nothing from the stream...
$stat = "403 Forbidden";
break;
}
}
}
fclose($stream);
}
What could I do to solve this issue? is there any thing to set in Windows to make it work or is it just my code who lacks something?
Windows will first create a 0-byte file. After this succeeds it will upload the entire file.