Rectangle 27 6

You can set the output's content type to text/plain to make browsers showing the content as, well, plain text like what you will see on CLI

header("Content-type: text/plain");

php - how to write new lines in CLI and web browser? - Stack Overflow

php
Rectangle 27 6

You can set the output's content type to text/plain to make browsers showing the content as, well, plain text like what you will see on CLI

header("Content-type: text/plain");

php - how to write new lines in CLI and web browser? - Stack Overflow

php
Rectangle 27 145

Try Eclipse PDT to setup an Eclipse environment that has debugging features like you mentioned. The ability to step into the code is a much better way to debug then the old method of var_dump and print at various points to see where your flow goes wrong. When all else fails though and all I have is SSH and vim I still var_dump()/die() to find where the code goes south.

Is there a way to beautify the "var_dump" ?

kill($data) { echo "<pre>"; var_dump($data); echo "</pre>"; exit; }

Link is "recoverable" via the incredible Web Archive, last check as of 7 may '15.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

eclipse - How do you debug PHP scripts? - Stack Overflow

php eclipse debugging phpstorm xdebug
Rectangle 27 5

Content-Type: application/json is just content header, the content header is just information about type of returned data, ex::JSON,image(png,jpg,etc..),html. Keep in mind, that JSON in javascript is an array or object. if you want to see all the data, use console.log instead of alert

alert(response.text);//will alert "[object Object]" string
console.log(response.text);//will logging all data object

if you want to alert original JSON as string, than add single quotation marks ('):

echo "'" . json_encode(array('text' => 'omrele')) . "'";
//alert(response.text) will alert {"text":"omrele"}

Do not use double quotes, it will confuse javascript, because JSON uses double quote on each value and key:

echo '<script>var returndata=';
echo '"' . json_encode(array('text' => 'omrele')) . '"';
echo ';</script>';

//it will return wrong javascript code: 
<script>var returndata="{"text":"omrele"}";</script>

javascript - HTTP Content-Type Header and JSON - Stack Overflow

javascript php json http
Rectangle 27 5

Content-Type: application/json is just content header, the content header is just information about type of returned data, ex::JSON,image(png,jpg,etc..),html. Keep in mind, that JSON in javascript is an array or object. if you want to see all the data, use console.log instead of alert

alert(response.text);//will alert "[object Object]" string
console.log(response.text);//will logging all data object

if you want to alert original JSON as string, than add single quotation marks ('):

echo "'" . json_encode(array('text' => 'omrele')) . "'";
//alert(response.text) will alert {"text":"omrele"}

Do not use double quotes, it will confuse javascript, because JSON uses double quote on each value and key:

echo '<script>var returndata=';
echo '"' . json_encode(array('text' => 'omrele')) . '"';
echo ';</script>';

//it will return wrong javascript code: 
<script>var returndata="{"text":"omrele"}";</script>

javascript - HTTP Content-Type Header and JSON - Stack Overflow

javascript php json http
Rectangle 27 6

In my case, I wanted to see .htaccess files, but not all the other .* resources. In Zend Studio for Eclipse, in PHP Explorer (not Remote System Explorer), click the downward facing arrow (next to the left/right arrows). Choose Filters. Uncheck .* resources In the "Name filter patterns" area, type the filenames you want to ignore. I used: .svn, .cvs, .DS_Store, .buildpath, .project

How can I get Eclipse to show .* files? - Stack Overflow

eclipse file hidden
Rectangle 27 6

In my case, I wanted to see .htaccess files, but not all the other .* resources. In Zend Studio for Eclipse, in PHP Explorer (not Remote System Explorer), click the downward facing arrow (next to the left/right arrows). Choose Filters. Uncheck .* resources In the "Name filter patterns" area, type the filenames you want to ignore. I used: .svn, .cvs, .DS_Store, .buildpath, .project

How can I get Eclipse to show .* files? - Stack Overflow

eclipse file hidden
Rectangle 27 4

The best you could hope for is to store both MD5 and SHA1 versions, and populate the SHA1 content when the user logs in. Just check to see if the SHA1 version is available, and if not use old validation strategy.

You should, eventually, migrate most of your users over to the new SHA1/SALT based system transparently.

php - Most efficient way to change the hash type of a password (md5 to...

php database hash md5 sha1
Rectangle 27 4

Yes, content will be returned, but the XHR object's readyState will not be set to 4, so if you are relying on that to update your div (which most JS libraries' AJAX auto updaters do), you won't see it automatically.

Neither with jQuery? :/

I don't think so. I have a feeling that what you want here is not AJAX but COMET (en.wikipedia.org/wiki/Comet_%28programming%29).

That's a really nice feature but isn't what i'm looking for.... yet.

php - If you flush the content (ob_flush) of an AJAX request, the cont...

php javascript jquery ajax output-buffering
Rectangle 27 10

I'm not intimately familiar with the workings of fileinfo, but I think this is normal. Text files (and that's what CSS and JS are) provide no clear pointers as to what content it has. They have no header bytes, no defined structure. So all poor fileinfo can do is guess - with poor results, as you can see.

I think to successfully verify the contents of .js and .css files, you have to either rely on the extension, or actually parse them with the correct, appropriate parser.

javascript - Php doesn't return the correct mime type - Stack Overflow

php javascript css mime-types mime
Rectangle 27 1

Well... the echos are the problems. Try adding these two lines at the start of your code, you'll see the problem:

error_reporting(E_ALL);
ini_set('display_errors',1);

content disposition - PHP - Force File Download Script - Not working i...

php content-disposition force-download
Rectangle 27 19

<?php
require('lib/fpdf/fpdf.php');

$pdf = new FPDF('P', 'pt', array(500,233));
$pdf->AddFont('Georgiai','','georgiai.php');
$pdf->AddPage();
$pdf->Image('lib/fpdf/image.jpg',0,0,500);
$pdf->SetFont('georgiai','',16);
$pdf->Cell(40,10,'Hello World!');

// email stuff (change data below)
$to = "myemail@example.com"; 
$from = "me@example.com"; 
$subject = "send email with pdf attachment"; 
$message = "<p>Please see the attachment.</p>";

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "test.pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));

// main header
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

// send message
mail($to, $subject, $body, $headers);

?>

thanks, works perfectly in Gmail, but in Outlook the email is a blank page and the message is a 2nd attachment... You know what's causing this?

Email PDF Attachment with PHP Using FPDF - Stack Overflow

php pdf attachment fpdf
Rectangle 27 19

<?php
require('lib/fpdf/fpdf.php');

$pdf = new FPDF('P', 'pt', array(500,233));
$pdf->AddFont('Georgiai','','georgiai.php');
$pdf->AddPage();
$pdf->Image('lib/fpdf/image.jpg',0,0,500);
$pdf->SetFont('georgiai','',16);
$pdf->Cell(40,10,'Hello World!');

// email stuff (change data below)
$to = "myemail@example.com"; 
$from = "me@example.com"; 
$subject = "send email with pdf attachment"; 
$message = "<p>Please see the attachment.</p>";

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "test.pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));

// main header
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

// send message
mail($to, $subject, $body, $headers);

?>

thanks, works perfectly in Gmail, but in Outlook the email is a blank page and the message is a 2nd attachment... You know what's causing this?

Email PDF Attachment with PHP Using FPDF - Stack Overflow

php pdf attachment fpdf
Rectangle 27 17

If you are dealing with images, use getimagesize. Unlike file_exists, this built-in function supports remote files. It will return an array that contains the image information (width, height, type..etc). All you have to do is to check the first element in the array (the width). use print_r to output the content of the array

$imageArray = getimagesize("http://www.example.com/image.jpg");
if($imageArray[0])
{
    echo "it's an image and here is the image's info<br>";
    print_r($imageArray);
}
else
{
    echo "invalid image";
}

Results in 404 warning when the remote resource is not available. For the time being, I handled it by suppressing error using @ in front of getimagesize, but feeling guilty for this hack.

In my case this was the best approach, because I get redirected whenever an image/file doesnt exist. I second that the suppressing errors with @ is a no go but in this case it was neccessary.

exif_imagetype

How can one check to see if a remote file exists using PHP? - Stack Ov...

php file networking testing
Rectangle 27 3

In response to your last comment I realise you cannot change Google's reCaptcha api - what I meant was simply to do a file_get_contents actually on example.com ( it does exist ) as a test to see if you can retrieve any content using that method as some webhosts disable the associated functionality.

However, with respect to the Google reCatcha API you might need to specify additional parameters to the file_get_contents function call, notably setting the context options specifically for SSL.

$secret = 'Your google secret';
$captcha = trim( $_POST['g-recaptcha-response'] );
$ip = $_SERVER['REMOTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$captcha}&remoteip={$ip}";

$options=array(
    'ssl'=>array(
        'cafile'            => '/path/to/cacert.pem',
        'verify_peer'       => true,
        'verify_peer_name'  => true,
    ),
);
$context = stream_context_create( $options );
$res=json_decode( file_get_contents( $url, FILE_TEXT, $context ) );
if( $res->success ){/* all good */}
else{ /* captcha failed */ }

If you don't already have a copy of cacert.pem or ca-bundle.crt you can download them from their respective links. The path to the cafile can use either - save a copy to your host and correct the path to suit your environment.

change the arrayname from http to ssl and adding the cert locally made it work, thank you .. look over at my next question about pass the params with a POST request ... stackoverflow.com/questions/33856354/

php - reCaptcha file_get_contents(): SSL operation failed - Stack Over...

php ssl file-get-contents recaptcha
Rectangle 27 4

My PHP is a bit rusty but I can think of one thing with your code, no content length header. Update your code to this and see if that works:

if (isset($_REQUEST['download'])) {
  {
    $download_id = $_REQUEST['download'];

    // ...

    $filename = $result->TrackPath;
    $outputfilename = $result->ArtisteName . ' ft. ' . $result->FeaturedArtistes . ' - ' . $result->TrackName . '.mp3';

    if (file_exists($filename)) {
      header("Content-Type:  audio/mpeg");
      header("Content-Disposition:  attachment; filename=\"" . basename($outputfilename) . "\";" );
      header("Content-Transfer-Encoding:  binary");

      header('Content-Length: ' . filesize($filename));
      ob_clean();
      flush();
      readfile($filename);
      exit;
    }
  }
}

Note that we use flush(); to send the headers to the browser before we start downloading the actual file. And I also added an if (file_exists($filename)) to make sure we have a file to send. I'd recommend you put an else clause there to give you something that will show you if you don't have a file like you expect...

great. works well. the code is clean.

html - Renaming Download File Using Header in PHP - Stack Overflow

php html mysql
Rectangle 27 4

My PHP is a bit rusty but I can think of one thing with your code, no content length header. Update your code to this and see if that works:

if (isset($_REQUEST['download'])) {
  {
    $download_id = $_REQUEST['download'];

    // ...

    $filename = $result->TrackPath;
    $outputfilename = $result->ArtisteName . ' ft. ' . $result->FeaturedArtistes . ' - ' . $result->TrackName . '.mp3';

    if (file_exists($filename)) {
      header("Content-Type:  audio/mpeg");
      header("Content-Disposition:  attachment; filename=\"" . basename($outputfilename) . "\";" );
      header("Content-Transfer-Encoding:  binary");

      header('Content-Length: ' . filesize($filename));
      ob_clean();
      flush();
      readfile($filename);
      exit;
    }
  }
}

Note that we use flush(); to send the headers to the browser before we start downloading the actual file. And I also added an if (file_exists($filename)) to make sure we have a file to send. I'd recommend you put an else clause there to give you something that will show you if you don't have a file like you expect...

great. works well. the code is clean.

html - Renaming Download File Using Header in PHP - Stack Overflow

php html mysql
Rectangle 27 1

You can use the REST API for worpdress (at http://v2.wp-api.org/ ) this way you can load the post content with ajax and append it to your div as you see fit

$.get('http://demo.wp-api.org/wp-json/wp/v2/posts/470',function(data){
    data = JSON.parse( data );
    $('div.selector').html( data.content );
})

php - Wordpress: Passing post content into div using AJAX - Stack Over...

php ajax wordpress
Rectangle 27 1

set location.href = a.php (as example). then set header content of that a.php file to csv type and then echo your csv file(see google help). Maybe this will help you. see header content for csv file for html page from google.

<?php header('Content-type:text/csv'); ?>

The same code is worning fine in my Windows XAMPP Server...

Is their any way to configure httpd.conf for prompting download for any csv file requested?? header("Content-type: text/x-csv"); header("Content-Disposition: attachment; filename=$filename"); Can content-Disposition configured in httpd.conf?

php - CSV File displayed by browser insteed of prompting download - St...

php ajax csv download httpd.conf
Rectangle 27 1

Let me see if I get it straight, you have something like this:

<div id="another-class"><div class="class">some text 1</div></div>
<div class="class">some text 2</div>
<div class="class">some text 3</div>
<div class="class">some text 4</div>
<div class="class">some text 5</div>
<div class="class">some text 6</div>

And you need the text contained the div elements. If this is correct, replace:

$activity = explode( '<div class="class">' , $content );
$activity_second = explode("</div>" , $activity );

with this:

preg_match_all('#<div class="class">(.+?)</div>#', $content, $matches);

In this example, after the function call $matches will have the following:

Array
(
    [0] => Array
        (
            [0] => <div class="class">some text 1</div>
            [1] => <div class="class">some text 2</div>
            [2] => <div class="class">some text 3</div>
            [3] => <div class="class">some text 4</div>
            [4] => <div class="class">some text 5</div>
            [5] => <div class="class">some text 6</div>
        )

    [1] => Array
        (
            [0] => some text 1
            [1] => some text 2
            [2] => some text 3
            [3] => some text 4
            [4] => some text 5
            [5] => some text 6
        )

)

The data you need is in $matches[1].

I did this and I'm getting the same as before just Array is being displayed on the website

You have got the concept correct though, that is what I am hoping to achieve

<?php $url = "http://domain.com"; $content = file_get_contents($url);  preg_match_all('#<div class="class">(.+?)</div>#', $content, $matches);  echo $matches[1]; ?>

$matches[1] is an array, so echoing it just like that won't work. For that you need a foreach statement, like this: foreach($matches[1] as $match) { echo $match; }

file get contents - php only retrieving one string from external div f...

php file-get-contents explode external-url