Welcome Guest, Not a member yet? Register   Sign In
Simple chat facility - if file exists not working
#1

(This post was last modified: 07-04-2020, 06:58 AM by christaliise.)

We are trying to build a simple chat facility without using a database & have got the basic facility to work between 2 uses.

However, we want to first search to see if there is already a previous chat session in existence, but cant get that to work.

This is what we have tried;

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Chat extends CI_Controller
{

public function 
index()
    {

        if(
file_exists("C:xampp/htdocs/application/views/john/chris/chat"))  // Also tried if(is_dir(
        
{
        
redirect('chris/john/chat');  // Also tried $this->load->view('chris/john/chat');
        
}
        else  
// This is always rejected
        


If the file does not exist then the Controller Files & View Files are created. That part works OK but needs further work.

Can anybody guide us as to what we are doing wrong?

UPDATE

Ive got the system working but I need to learn how to get the scroll bar at the bottom.

I want to get the scroll bar at the bottom when the page is opened, instead of the top by default. From my research CSS does not facilitate that. The following is my current coding;

PHP Code:
<style type="text/css"> .mem positionfixedwidth53%; left46%; top30%; font-familyarialfont-size100%; colorBlackbottom3.7%; overflowauto; } </style>
<
div class="mem"

I would like a simple instruction like in the following, but that does not work;

PHP Code:
<style type="text/css"> .mem positionfixedwidth53%; left46%; top30%; font-familyarialfont-size100%; colorBlackbottom3.7%; overflowautoscrollToBottom; } </style

From my research it is only achievable by Javascript.

Ive searched the following & acquired the coding below but they dont work;
https://stackoverflow.com/questions/1861...scrolls-up

PHP Code:
var element document.getElementById("yourDivID");
element.scrollTop element.scrollHeight;
<
script> var element document.getElementById("mem"); element.scrollTop element.scrollHeight; </script

https://stackoverflow.com/questions/7063...-to-bottom
The Javascript code below should keep your div's scrollbar positioned at the bottom like you described:

PHP Code:
var objDiv document.getElementById("divExample");
objDiv.scrollTop objDiv.scrollHeight;
<
script> var objDiv document.getElementById("mem"); objDiv.scrollTop objDiv.scrollHeight; </script
Reply
#2

It wont work because the whole application folder is using an .htaccess file
to stop viewing it. Look at the ,htaccess file.

What you would need to do is move it all to the root folder were it is writable.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(06-22-2020, 03:57 AM)InsiteFX Wrote: It wont work because the whole application folder is using an .htaccess file
to stop viewing it. Look at the ,htaccess file.

What you would need to do is move it all to the root folder were it is writable.

Thanks InsiteFX. Obviously I need to learn more about .htaccess files. I have found 2.

C:xampp/htdocs/application/.htaccess
PHP Code:
<IfModule authz_core_module>
    Require 
all denied
</IfModule>
<
IfModule !authz_core_module>
    
Deny from all
</IfModule

C:xampp/htdocs/.htaccess
PHP Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond 
$!^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
^(.*)$ /index.php?/$[L]
</
IfModule>
Header add Access-Control-Allow-Origin "*" 

I assume the root folder you speak of, is C:xampp/htdocs

I need to keep the chat files separate from the many base files Ive created for the website proper.

Is it wise to create chatterbox folders like C:xampp/htdocs/application/views/chatterbox/john/chris/chat & C:xampp/htdocs/application/controllers/Chatterbox/John/Chris/Chat and place a .htaccess file in the Chatterbox folder?
Reply
#4

(This post was last modified: 06-22-2020, 11:02 AM by jreklund.)

@christaliise: What exactly dosen't work? It dosen't find the file?

This are the correct way of building a path.
PHP Code:
APPPATH.'views'.DIRECTORY_SEPARATOR.'john'.DIRECTORY_SEPARATOR.'chris'.DIRECTORY_SEPARATOR.'chat'

redirect will however not work, unless you have a controller that's named chris.
Reply
#5

(06-22-2020, 11:02 AM)jreklund Wrote: @christaliise: What exactly dosen't work? It dosen't find the file?

This are the correct way of building a path.
PHP Code:
APPPATH.'views'.DIRECTORY_SEPARATOR.'john'.DIRECTORY_SEPARATOR.'chris'.DIRECTORY_SEPARATOR.'chat'

redirect will however not work, unless you have a controller that's named chris.

Thanks jreklund.

I want first a search for the file, if it is found, then redirect, to 'chris/john/chat' (keep in mind it is chris that is logged in) page where the previous conversations will be exposed. That does not work as it redirects whether or not the file exists.

If the file is not found then it creates the 'chris/john/chat' & 'john/chris/chat' Controllers & view pages. The conversations can begin. That part I have working but it needs attention particularly in the variables for example.
PHP Code:
$lcuser $this->session->userdata('user_name');
$ucuser ucfirst("$lcuser"); 

redirect is not a problem. Yes, I have Controllers for all the pages, for example Controllers for "Chris/Chat", "John/Chat", "Chris/John/Chat, & John/Chris/Chat.

I dont understand your "correct way of building a path"? Can you explain?

I guess by "DIRECTORY_SEPARATOR" you mean forward slash? [/]. But I notice your full stops & single quotes ['.].

When doing a fwrite I use double quotes, spaces & full stops [" . ].
Reply
#6

This code:
APPPATH.'views'.DIRECTORY_SEPARATOR.'john'.DIRECTORY_SEPARATOR.'chris'.DIRECTORY_SEPARATOR.'chat';

Are the same as:
"C:\xampp\htdocs\application\views\john\chris\chat"

But it will work on all servers and operating systems. And if you ever move your folder, it will be found automatically, no need to change it manually every time. DIRECTORY_SEPARATOR will either generate / or \ depending of operating system. \ for Windows and / for Linux.

At the moment you are missing one / (actually should be \), in case you want to hard-code it.

Your code:
"C:xampp/htdocs/application/views/john/chris/chat"

Should be:
"C:\xampp\htdocs\application\views\john\chris\chat"
Reply
#7

If chat is the view file and not a folder you will need to add the .php extension also
when checking if the file exists.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

(06-22-2020, 02:09 PM)jreklund Wrote: This code:
APPPATH.'views'.DIRECTORY_SEPARATOR.'john'.DIRECTORY_SEPARATOR.'chris'.DIRECTORY_SEPARATOR.'chat';

Are the same as:
"C:\xampp\htdocs\application\views\john\chris\chat"

But it will work on all servers and operating systems. And if you ever move your folder, it will be found automatically, no need to change it manually every time. DIRECTORY_SEPARATOR will either generate / or \ depending of operating system. \ for Windows and / for Linux.

At the moment you are missing one / (actually should be \), in case you want to hard-code it.

Your code:
"C:xampp/htdocs/application/views/john/chris/chat"

Should be:
"C:\xampp\htdocs\application\views\john\chris\chat"

Hi jreklund, do you know anything about Javascript. Ive updated my post wanting to know how to get the scroll bar at the bottom. Can you help?
Reply
#9

Hi, I'm afraid it too hard to see and answer without seeing it in real time.
Can you construct a working demo at JSFiddle?
Reply
#10

(07-05-2020, 04:51 AM)jreklund Wrote: Hi, I'm afraid it too hard to see and answer without seeing it in real time.
Can you construct a working demo at JSFiddle?

I dont know much about JSFiddle although I have been there. If you open many website pages including this one in this forum the scroll bar is at the top by default but because PHP does not facilitate the pasting of text part way into a page the only thing that can be done is to paste at the bottom when using fwrite. Therefore I want the scroll bar to be at the bottom when the page is opened, to avoid users having to scroll down each time they open the page.

There are some sites that do that such as https://www.carousell.ph in their chat facility. That site obviously uses PHP.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB