php-chat | A Ridicolous php chat , used for demo with Docker | Chat library
kandi X-RAY | php-chat Summary
kandi X-RAY | php-chat Summary
This is a very simple php chat running with php.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of php-chat
php-chat Key Features
php-chat Examples and Code Snippets
Community Discussions
Trending Discussions on php-chat
QUESTION
I am new to web-sockets. I am trying to establish communication between client and server through web-socket. I follow the code from this link:
https://phppot.com/php/simple-php-chat-using-websocket/
Here is my try:
- Client JS side:
var ws = new WebSocket("ws://myIp:8090");
- Server PHP side:
define('HOST_NAME',"myIP");
define('PORT',"8090");
Now in the browser when I go for,
http://localhost:8090
: The initial handshake Request Headers in browser:
Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9 Cache-Control: no-cache Connection: Upgrade Host: myIP:8090 Origin: http://localhost:8090 Pragma: no-cache Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Sec-WebSocket-Key: tJ0fWdCEfJCUcmtRCNOJuQ== Sec-WebSocket-Version: 13 Upgrade: websocket User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
And Response headers in PHP Server is:
HTTP/1.1 101 Web Socket Protocol Handshake Upgrade: websocket Connection: Upgrade WebSocket-Origin: myIP WebSocket-Location: ws://myIP:8090/demo/shout.php Sec-WebSocket-Accept:DqaK+Z+jqf1lJ0vj5bIxFi7+EPc=
As in above both request and response headers upgrade their protocol to web-socket and communication establish successfully.
http://myIP:8090
:
Request Headers are in browser:
Provisional headers are shown Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9 Cache-Control: no-cache Connection: Upgrade Host: myIP:8090 Origin: http://myIP:8090 Pragma: no-cache Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Sec-WebSocket-Key: D73LNcTLB8P6dzPilGipQQ== Sec-WebSocket-Version: 13 Upgrade: websocket User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
but the PHP server receives the Request Headers are:
GET / HTTP/1.1 Host: localhost:8090 Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36 Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9 Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9 If-None-Match: W/"41e-5e6jpMk0FNkw+DjhkfcoeaiAhE4"
As seen above the PHP Server does not receive the web-socket upgrade headers sent by the browser. So the server does not receive any Sec-WebSocket-Key
in request headers and got this error:
ErrorException: Undefined index: Sec-WebSocket-Key
while creating the response headers. I dont know how this can be tackled? How does the Request Headers are getting modified? Have I done something wrong in the setup? And can this setup work to establish the communication on two different PC's? Please Help. Thanks in Advance!
...ANSWER
Answered 2020-Nov-23 at 11:55After some try here and there I found the way to communicate through Web-sockets in the same or different PC's.
- If the server and Client are in the same PC: The
case 1
will be worked from the above question. - If the server and client are in the different PC's: In the Client(JS) side set the IP address to the Server PC IP will work.
Client JS side:
var ws = new WebSocket("ws://Server_PC_IP:8090");
QUESTION
So I have this basic chat loaded up, built with jQuery and php (not by me) and I have changed it a little. Just to fit my purpose. Text is put in a textarea tag and then sent. I would like to have secret commands where you type a phrase and it does cool stuff. Such as typing "red" will make your name red. (I have already made script for this, just need to run it when somebody types red). What would I need to allow this? Chat: https://css-tricks.com/jquery-php-chat/ Thanks
...ANSWER
Answered 2019-Jun-20 at 02:00The code snippet below gives an example of how you can accomplish this task. You leverage textarea
's oninput
attribute to bind a function that looks at the contents of the text area. You can then do whatever you want with this, like calling your red
function when the text is red
.
QUESTION
I'm trying to run iFlyChat with Symfony using their PHP client https://iflychat.com/installation/php-chat-client which I have successfully install using composer.
I've created an extension for the code:
...ANSWER
Answered 2017-Feb-10 at 08:35Have a look at vendor/composer/autoload_psr4.php
so you can make sure there is an autoload namespace generated for IflyChat.
If there isn't you can execute:
composer dump-autoload
to force composer to regenerate the autoload for your dependencies.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install php-chat
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page