CodeIgniter Forums
loading issue after logout - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: loading issue after logout (/showthread.php?tid=63261)



loading issue after logout - ardavan - 10-12-2015

Hi guys,

Im currently working on a project that has member system.
At home page will appear some images from Database and the directory.
The issue is once i logout the page will redirect to home page but the images won't load and i can see the images are missing.

Im testing on my localhost.
Is the issue about my code?

Here is my logout function:
PHP Code:
function logout()
    {
        
$this->session->sess_destroy();
        
$this->cart->destroy();

        
redirect('/');
    } 

Any idea?

Thanks


RE: loading issue after logout - JayAdra - 10-12-2015

How are your images being loaded? Can you post the code for them? It may be they are loaded with relative paths (e.g. images/1.jpg) rather than absolute paths (e.g. http://example.com/images/1.jpg or /images/1.jpg).


RE: loading issue after logout - Baslugten - 10-12-2015

Try base_url()


RE: loading issue after logout - ardavan - 10-12-2015

I'm doing like /images/1.jpg

after change it to absolute its working well. But why this happened? is it only on localhost or if i upload on the host will be the same.
Because I'm wonder, after logout the images gone then i refresh, they appear!

Thank you for your help.


RE: loading issue after logout - mwhitney - 10-13-2015

It will be the same on the host. You should always use absolute URLs for links and src attributes, using a function like base_url() or site_url() so the correct URL is generated for the current environment.

Something else you should consider is using redirect() with no arguments rather than '/', since the slash is likely the difference between before and after you logout. In other words, since you supplied a relative URL of '/images/1.jpg' and you probably started at 'http://www.example.com', your image would be found at 'http://www.example.com/images/1.jpg'. When you called redirect('/'), you probably ended up at 'http://www.example.com/', and it looks for your image at 'http://www.example.com//images/1.jpg'. Since it's fairly common for people to end up at 'http://www.example.com/', you don't want this to happen when people visit the page using this URL.

You can also set the base URL in your HTML to give yourself a fixed reference for relative URLs, regardless of the URL the user is currently viewing: http://www.w3.org/TR/html5/document-metadata.html#the-base-element