chatbox
Op de site kunnen alleen ingelogde mensen die chatbox gebruiken (en alleen bij hun word hij weergeven). De inlog&Registratie gegevens moeten opgeslagen kunnen worden in de database v/d site.
Hoe krijg ik dit voor elkaar/waar kan ik een soortgelijke downloadbare chatbox vinden?
In dat geval zul je moeten kijken naar node.js en een eigen webserver. Of je kan je verdiepen in IRC; een chatprotocol, en een IRC-client downloaden (zoals Mibbit).
Ik ben er ook veel tegen gekomen maar het is steeds niet wat ik zoek. Het liefst noet de chatnaam van de gebruiker hetzelfde zijn als de accounaccountnaam waarop diegene ingelogd is, zonder dat diegene nog een extra x in de chat box zijn wachtwoord en naam hoeft in te vullen. Ook moet er een mogelijkheid zijn voor privechats.
Bij elke chatbox kan de gebruiker een chatnaam bedenken. In dit geval moet je de chatbox aanpassen dat hij de juiste username uit je sessie of database haalt.
Weet iemand een goedwerkende chatbox waar ik hetgeen mee kan wat ik al uitgelegd had? Heb er heel veel uitgeprobeerd, maar de meesten zijn het net niet.
https://www.google.com/?gws_rd=ssl#q=chatbox+php
En anders als je niks kan vinden, wat houdt je tegen om het zelf te bouwen?
PHP etc kan ik opzich prima, maar Javascript is een heel ander verhaal.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
session_start(); // Start a new session
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
?><?php
include('conn.php');
if(isset($_GET['set']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
($_GET['uid']=='1')? $color ="red" : $color ="green";
$insert1 = "INSERT INTO chat (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$get2 = "select * from users where user_id= 'id' and displayed=0";
mysql_query($get2);
echo "<br><font color=$color><b>User" . $row['username'] . " </b>";
mysql_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;
}
}
else if(isset($_GET['get']))
{
$get = "select * from chat where user_id= 'id' and displayed=0";
$res = mysql_query($get);
$num_rows = mysql_num_rows($res);
if($num_rows)
{
while($new_msg = mysql_fetch_array($res))
echo "<br><font color=\"$color\"><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$mark2 = mysql_query("update chat set displayed=1 where user_id=".$id." and displayed=0");
}
}
else
{
echo "<font color=red><b><br>Error processing data...!</b></font>";
}
function add_smilies($str_msg)
{
$get_smiles = mysql_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysql_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysql_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysql_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
?>
session_start(); // Start a new session
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
?><?php
include('conn.php');
if(isset($_GET['set']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
($_GET['uid']=='1')? $color ="red" : $color ="green";
$insert1 = "INSERT INTO chat (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$get2 = "select * from users where user_id= 'id' and displayed=0";
mysql_query($get2);
echo "<br><font color=$color><b>User" . $row['username'] . " </b>";
mysql_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;
}
}
else if(isset($_GET['get']))
{
$get = "select * from chat where user_id= 'id' and displayed=0";
$res = mysql_query($get);
$num_rows = mysql_num_rows($res);
if($num_rows)
{
while($new_msg = mysql_fetch_array($res))
echo "<br><font color=\"$color\"><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$mark2 = mysql_query("update chat set displayed=1 where user_id=".$id." and displayed=0");
}
}
else
{
echo "<font color=red><b><br>Error processing data...!</b></font>";
}
function add_smilies($str_msg)
{
$get_smiles = mysql_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysql_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysql_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysql_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
?>
Toevoeging op 16/03/2015 19:36:00:
Alleen in de chat zegt hij:
"Notice: Undefined variable: row in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 26"
Hoe kan dit?
Deze werkt op userID's, en verder is er een SQL-injection mogelijk op lijn 22.
Probeer het query resultaat eerst even te fetchen naar de variabele $row, dan gaat het vast beter.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
session_start(); // Start a new session
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
$conn = mysqli_connect("localhost","root","superbart","blog") or die("could not connect to server");
if(isset($_GET['set']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
($_GET['uid']=='1')? $color ="red" : $color ="green";
$insert1 = "INSERT INTO chat (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "select * from users where user_id= 'id' and displayed=0";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><font color=$color><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;}
}
}
else if(isset($_GET['get']))
{
$query = "select * from chat where user_id= 'id' and displayed=0";
$result = mysqli_query($conn, $query);
$num_rows = mysqli_num_rows($result);
if($num_rows)
{
while($new_msg = mysqlifetch_array($res))
echo "<br><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$query = "select * from users where user_id= 'id' and displayed=0";
$mark2 = mysqli_query($query);
}
}
else
{
echo "<font color=red><b><br>Error processing data...!</b></font>";
}
function add_smilies($str_msg)
{
$get_smiles = mysql_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysql_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysql_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysql_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
?>
session_start(); // Start a new session
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
$conn = mysqli_connect("localhost","root","superbart","blog") or die("could not connect to server");
if(isset($_GET['set']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
($_GET['uid']=='1')? $color ="red" : $color ="green";
$insert1 = "INSERT INTO chat (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "select * from users where user_id= 'id' and displayed=0";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><font color=$color><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;}
}
}
else if(isset($_GET['get']))
{
$query = "select * from chat where user_id= 'id' and displayed=0";
$result = mysqli_query($conn, $query);
$num_rows = mysqli_num_rows($result);
if($num_rows)
{
while($new_msg = mysqlifetch_array($res))
echo "<br><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$query = "select * from users where user_id= 'id' and displayed=0";
$mark2 = mysqli_query($query);
}
}
else
{
echo "<font color=red><b><br>Error processing data...!</b></font>";
}
function add_smilies($str_msg)
{
$get_smiles = mysql_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysql_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysql_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysql_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
?>
Toevoeging op 16/03/2015 20:12:53:
laatste foutwarning tot nu toe:
"Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 39"
Gewijzigd op 16/03/2015 20:18:14 door bart de kinkelaar
chatbox ergens liggen.
Als je interesse hebt PM me maar dan kan ik deze zoeken voor je.
Ik had ergens nog de source van deze Als je interesse hebt PM me maar dan kan ik deze zoeken voor je.
Bart de kinkelaar op 16/03/2015 20:08:21:
laatste foutwarning tot nu toe:
"Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 39"
"Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 39"
je query wilt niet uitgevoerd worden omdat er foutafhandeling ontbreekt.
Kijk eens naar mysqli_error($con);
Je vergelijkt in deze query de inhoud van de kolom user_id met de string 'id', dit moet vast de variabele $id zijn.
Dit zal geen foutmelding geven maar wel een leeg resultaat,
Gewijzigd op 16/03/2015 23:01:48 door Pipo Clown
Op dit moment heb ik vooral deze error:
Notice: Undefined variable: id in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 41
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
session_start(); // Start a new session?><?php
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
?><?php
$conn = mysqli_connect("localhost","root","superbart","minimail") or die("could not connect to server");
if(isset($_GET['set']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
($_GET['uid']=='1')? $color ="red" : $color ="green";
$insert1 = "INSERT INTO chat (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "select * from users where user_id= $id";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><font color=$color><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error();
}
}
else if(isset($_GET['get']))
{
$query2 = "select * FROM users WHERE user_id= $id";
$result2 = mysqli_query($conn,$query2) or die ( mysql_error() );
$num_rows = mysqli_num_rows($result2);
if ($nrOfRows > 0)
{
while($new_msg = mysqlifetch_array($result))
echo "<br><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$query = "select * from users where user_id= $id";
$result = mysqli_query($query);
}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error();
}
function add_smilies($str_msg)
{
$get_smiles = mysql_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysql_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysql_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysql_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
?>
session_start(); // Start a new session?><?php
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}
?><?php
$conn = mysqli_connect("localhost","root","superbart","minimail") or die("could not connect to server");
if(isset($_GET['set']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
($_GET['uid']=='1')? $color ="red" : $color ="green";
$insert1 = "INSERT INTO chat (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "select * from users where user_id= $id";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><font color=$color><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error();
}
}
else if(isset($_GET['get']))
{
$query2 = "select * FROM users WHERE user_id= $id";
$result2 = mysqli_query($conn,$query2) or die ( mysql_error() );
$num_rows = mysqli_num_rows($result2);
if ($nrOfRows > 0)
{
while($new_msg = mysqlifetch_array($result))
echo "<br><b>User ".$id." </b>[".$new_msg['timestamp']."] <b>: </b></font>".stripslashes($new_msg['msg']);
$query = "select * from users where user_id= $id";
$result = mysqli_query($query);
}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error();
}
function add_smilies($str_msg)
{
$get_smiles = mysql_query("select * from smilies order by length(image_code) desc");
while($row_smilies = mysql_fetch_array($get_smiles))
{
$str_msg = str_replace(''.$row_smilies['image_code'].''," <img src='images/".$row_smilies['id'].".gif'> ",$str_msg);
//$str_msg = preg_match("/".$row_smilies['image_code']."/","<img src='images/".$row_smilies['id'].".gif'>");
/*if(false !== strpos($row_smilies['image_code'],$str_msg))
{
$sel = mysql_query("select * from smilies where image_code='".$row_smilies['image_code']."'");
$row = mysql_fetch_array($sel);
echo "<img src='images/".$row_smilies['id'].".gif'>";
}*/
}
return $str_msg;
}
?>
Gewijzigd op 17/03/2015 16:01:21 door bart de kinkelaar
Hint 2: Kijk eens hier onder het kopje Return Values.
Notice: Undefined variable: id in C:\xampp\htdocs\Webwinkelcentrum\MMchat3\script_page.php on line 40
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Laat ik mysql_error staan en is dit de code:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
if(isset($_GET['set']))
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
($_GET['uid']=='1')? $color ="red" : $color ="green";
$insert1 = "INSERT INTO chat (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "select * from users where user_id= $id";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><font color=$color><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error();
{
if(isset($_GET['content']))
{
$str_msg = stripslashes($_GET['content']);
$time = getdate();
$str_msg = add_smilies($str_msg);
$t_stamp = $time['hours'].":".$time['minutes'].":".$time['seconds'];
($_GET['uid']=='1')? $color ="red" : $color ="green";
$insert1 = "INSERT INTO chat (user_id,msg,timestamp,displayed)
VALUES ('".$_GET['uid']."', '".addslashes($str_msg)."', '$t_stamp', '0')";
$query = "select * from users where user_id= $id";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result)) {
echo "<br><font color=$color><b>User" . $row['username'] . " </b>";}
$result = mysqli_query($conn,$insert1);
while($row = mysqli_fetch_array($result)) {
mysqli_query($insert1);
echo "[".$t_stamp."] <b>: </b></font>".$str_msg;}
}
else
{
echo "Failed to connect to MySQL: " . mysqli_error();
dan weergeeft hij de oude error.
De conn klopt en het ophalen van het ID zou ook moeten kloppen. Achter de link staat ?id=1 en bovenaan de code staat:
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
session_start(); // Start a new session
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}[/code]
session_start(); // Start a new session
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
// getting info from db
}[/code]
- Uitlijning is niet netjes, als ik accolades boven recht boven elkaar zie, dan is het script al lastig te debuggen
- MQL-functies benoemen we met een hoofdletter, dus SELECT i.p.v. select
- Gebruik van addslashes() waarmee je je input kan verminken. Gebruik gewoon mysqli_real_escape_string() voor $_POST, $_GEt en $_COOKIE in een query.
- $insert1 zegt niet veel, zie jij straks het verschil nog met $insert3 en $insert8? Noem hem dan bijvoorbeeld $insert_message.
- <font> is verouderd, kijk eens naar CSS.
Als je dat krijgt doe dan even de query echo-en en kijk eens hoe dat er uit ziet
Aar C op 17/03/2015 16:31:45:
Op het eerste ogenblik zie ik ook niet waarom die $id niet zou bestaan.
Als de GET niet bestaat ook geen $id.