<?php
$ip      = '10.15.18.22';   // ← change to your actual printer IP
$port    = 80;
$timeout = 4;

echo "<h2>Printer Test: $ip:$port</h2>";

$fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if ($fp) {
    echo "<p style='color:green'>✓ Port 9100 OPEN</p>";

    $esc  = "\x1B\x40";
    $cp   = "\x1B\x74\x00";
    $cut  = "\x1D\x56\x42\x00";

    $text = $esc . $cp
          . "\x1B\x61\x01"
          . "\x1B\x21\x10"
          . "THERMAL TEST\n"
          . "\x1B\x21\x00"
          . "\x1B\x61\x00"
          . str_repeat('-', 48) . "\n"
          . "Port 9100 is working!\n"
          . "Date: " . date('Y-m-d H:i:s') . "\n"
          . str_repeat('-', 48) . "\n"
          . "\n\n\n"
          . $cut;

    fwrite($fp, $text);
    fclose($fp);
    echo "<p style='color:green'>✓ Data sent — did it print cleanly?</p>";
} else {
    echo "<p style='color:red'>✗ Cannot connect: $errstr ($errno)</p>";
}
?>