tamhoangdk Posted April 3, 2016 Share Posted April 3, 2016 (edited) code below, when I use on hostinger it works, but on byethost7.com it was error this demo erro: http://code1996.byethost7.com/chat/ please help me, thank bro Edited April 3, 2016 by tamhoangdk Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/ Share on other sites More sharing options...
Jacques1 Posted April 3, 2016 Share Posted April 3, 2016 (edited) To clarify a few things: We will not download fishy ZIP archives from external websites. If you want help, post your code here on this forum inside a code section. That's the blue “<>” button: This is code We're no machine were you insert broken code and get the repaired code back. We expect you to actively work on the problem and give us a proper description of the issue. You might want to stop calling people “bro”. Edited April 3, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532750 Share on other sites More sharing options...
tamhoangdk Posted April 3, 2016 Author Share Posted April 3, 2016 Jacques sorry I do not know. let me try again Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532752 Share on other sites More sharing options...
tamhoangdk Posted April 3, 2016 Author Share Posted April 3, 2016 (edited) this file index.php <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Chat Box</title> <style type="text/css"> <!-- .shout_box { background: #627BAE; width: 260px; overflow: hidden; position: fixed; bottom: 0; right: 20%; z-index:9; } .shout_box .header .close_btn { background: url(images/close_btn.png) no-repeat 0px 0px; float: right; width: 15px; height: 15px; } .shout_box .header .close_btn:hover { background: url(images/close_btn.png) no-repeat 0px -16px; } .shout_box .header .open_btn { background: url(images/close_btn.png) no-repeat 0px -32px; float: right; width: 15px; height: 15px; } .shout_box .header .open_btn:hover { background: url(images/close_btn.png) no-repeat 0px -48px; } .shout_box .header{ padding: 5px 3px 5px 5px; font: 11px 'lucida grande', tahoma, verdana, arial, sans-serif; font-weight: bold; color:#fff; border: 1px solid rgba(0, 39, 121, .76); border-bottom:none; cursor: pointer; } .shout_box .header:hover{ background-color: #627BAE; } .shout_box .message_box { background: #FFFFFF; height: 200px; overflow:auto; border: 1px solid #CCC; } .shout_msg{ margin-bottom: 10px; display: block; border-bottom: 1px solid #F3F3F3; padding: 0px 5px 5px 5px; font: 11px 'lucida grande', tahoma, verdana, arial, sans-serif; color:#7C7C7C; } .message_box:last-child { border-bottom:none; } time{ font: 11px 'lucida grande', tahoma, verdana, arial, sans-serif; font-weight: normal; float:right; color: #D5D5D5; } .shout_msg .username{ margin-bottom: 10px; margin-top: 10px; } .user_info input { width: 98%; height: 25px; border: 1px solid #CCC; border-top: none; padding: 3px 0px 0px 3px; font: 11px 'lucida grande', tahoma, verdana, arial, sans-serif; } .shout_msg .username{ font-weight: bold; display: block; } --> </style> <script type="text/javascript" src="js/jquery-1.9.0.min.js"></script> <script type="text/javascript"> $(document).ready(function() { // load messages every 1000 milliseconds from server. load_data = {'fetch':1}; window.setInterval(function(){ $.post('shout.php', load_data, function(data) { $('.message_box').html(data); var scrolltoh = $('.message_box')[0].scrollHeight; $('.message_box').scrollTop(scrolltoh); }); }, 1000); //method to trigger when user hits enter key $("#shout_message").keypress(function(evt) { if(evt.which == 13) { var iusername = $('#shout_username').val(); var imessage = $('#shout_message').val(); post_data = {'username':iusername, 'message':imessage}; //send data to "shout.php" using jQuery $.post() $.post('shout.php', post_data, function(data) { //append data into messagebox with jQuery fade effect! $(data).hide().appendTo('.message_box').fadeIn(); //keep scrolled to bottom of chat! var scrolltoh = $('.message_box')[0].scrollHeight; $('.message_box').scrollTop(scrolltoh); //reset value of message box $('#shout_message').val(''); }).fail(function(err) { //alert HTTP server error alert(err.statusText); }); } }); //toggle hide/show shout box $(".close_btn").click(function (e) { //get CSS display state of .toggle_chat element var toggleState = $('.toggle_chat').css('display'); //toggle show/hide chat box $('.toggle_chat').slideToggle(); //use toggleState var to change close/open icon image if(toggleState == 'block') { $(".header div").attr('class', 'open_btn'); }else{ $(".header div").attr('class', 'close_btn'); } }); }); </script> </head> <body> <div class="shout_box"> <div class="header">Saaraan Shout Box <div class="close_btn"> </div></div> <div class="toggle_chat"> <div class="message_box"> </div> <div class="user_info"> <input name="shout_username" id="shout_username" type="text" placeholder="Your Name" maxlength="15" /> <input name="shout_message" id="shout_message" type="text" placeholder="Type Message Hit Enter" maxlength="100" /> </div> </div> </div> </body> </html> this shout.php <?php ####### db config ########## $db_username = '***********'; $db_password = '***********'; $db_name = '***********'; $db_host = '***********'; ####### db config end ########## if($_POST) { //connect to mysql db $sql_con = mysqli_connect($db_host, $db_username, $db_password,$db_name)or die('could not connect to database'); //check if its an ajax request, exit if not if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { die(); } if(isset($_POST["message"]) && strlen($_POST["message"])>0) { //sanitize user name and message received from chat box //You can replace username with registerd username, if only registered users are allowed. $username = filter_var(trim($_POST["username"]),FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH); $message = filter_var(trim($_POST["message"]),FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH); $user_ip = $_SERVER['REMOTE_ADDR']; //insert new message in db if(mysqli_query($sql_con,"INSERT INTO shout_box(user, message, ip_address) value('$username','$message','$user_ip')")) { $msg_time = date('h:i A M d',time()); // current time echo '<div class="shout_msg"><time>'.$msg_time.'</time><span class="username">'.$username.'</span><span class="message">'.$message.'</span></div>'; } // delete all records except last 10, if you don't want to grow your db size! mysqli_query($sql_con,"DELETE FROM shout_box WHERE id NOT IN (SELECT * FROM (SELECT id FROM shout_box ORDER BY id DESC LIMIT 0, 10) as sb)"); } elseif($_POST["fetch"]==1) { $results = mysqli_query($sql_con,"SELECT user, message, date_time FROM (select * from shout_box ORDER BY id DESC LIMIT 10) shout_box ORDER BY shout_box.id ASC"); while($row = mysqli_fetch_array($results)) { $msg_time = date('h:i A M d',strtotime($row["date_time"])); //message posted time echo '<div class="shout_msg"><time>'.$msg_time.'</time><span class="username">'.$row["user"].'</span> <span class="message">'.$row["message"].'</span></div>'; } } else { header('HTTP/1.1 500 Are you kiddin me?'); exit(); } } when finished code. error is: 403 access denied Edited April 3, 2016 by Barand remove db credentials Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532753 Share on other sites More sharing options...
Strider64 Posted April 3, 2016 Share Posted April 3, 2016 You should be posting a password....leave it blank or put ***** as a replacement. Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532754 Share on other sites More sharing options...
Jacques1 Posted April 3, 2016 Share Posted April 3, 2016 (edited) Change the database credentials immediately, because the posts will still be archived on Google. As to your problem: Does the Unix user of the webserver (usually www) have read permission on the shout.php script? Is there any .htaccess file or webserver configuration which blocks access to the script? Your query is also wide open to SQL injection attacks. Learn to use prepared statements. Edited April 3, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532755 Share on other sites More sharing options...
tamhoangdk Posted April 3, 2016 Author Share Posted April 3, 2016 my web dont have .htacscess file Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532756 Share on other sites More sharing options...
Jacques1 Posted April 3, 2016 Share Posted April 3, 2016 You've marked the topic as solved, but appearently you still have the problem. Did you click the button accidentally? my web dont have .htacscess file You need to read the other parts of my reply as well. Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532757 Share on other sites More sharing options...
tamhoangdk Posted April 3, 2016 Author Share Posted April 3, 2016 its really knew nothing about php . I only know the basics only. or help you to see yourself Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532759 Share on other sites More sharing options...
Jacques1 Posted April 3, 2016 Share Posted April 3, 2016 Right now, none of your tasks have anything to do with PHP. So, what are the file permissions? Does the webserver even have read access to the script? Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532761 Share on other sites More sharing options...
tamhoangdk Posted April 3, 2016 Author Share Posted April 3, 2016 this all file Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532762 Share on other sites More sharing options...
tamhoangdk Posted April 3, 2016 Author Share Posted April 3, 2016 this all files Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532763 Share on other sites More sharing options...
Jacques1 Posted April 3, 2016 Share Posted April 3, 2016 (edited) Check the error log of your webserver. Maybe there's a more detailed error message. Can your webserver execute any PHP scripts? When you upload a simple "Hello world" script, does that work correctly? Edited April 3, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532764 Share on other sites More sharing options...
tamhoangdk Posted April 3, 2016 Author Share Posted April 3, 2016 I don't know script simple "Hello world" Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532765 Share on other sites More sharing options...
tamhoangdk Posted April 3, 2016 Author Share Posted April 3, 2016 code1996.byethost7.com/chat/index.php Quote Link to comment https://forums.phpfreaks.com/topic/301143-please-help-me-this-code/#findComment-1532766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.