• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loading issue after logout

#1
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
Reply

#2
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).
Reply

#3
Try base_url()
Reply

#4
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.
Reply

#5
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-meta...se-element
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.