Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts

    redirect not working

    Hi,

    I am trying to secure my pages but my redirect isn't working?!

    PHP Code:
    if($row['SiteID'] == ""){

    session_destroy();

    // Redirect:
    header("Location: /index.php");

    Please help!

    ta

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    I use this on my site
    in the login function i set this on sucess
    PHP Code:
    $_SESSION['logged_in'] == true
    and at the top of each page
    PHP Code:

        
    if ($_SESSION['logged_in'] != true) {
            
    header('Location: index.php?ComeFrom='.$_SERVER['PHP_SELF']);
            exit;
        } 
    edit:

    and on the login page (index.php)

    PHP Code:

    if ((isset($_GET['ComeFrom'])) && ($_GET['ComeFrom'] != "")) {
                
    header('Location: ' $_GET['ComeFrom']);
                exit;
            } 
    Last edited by Arcticwarrio; 06-26-2013 at 12:08 PM.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by jarv81178 View Post
    PHP Code:
    header("Location: /index.php"); 
    I suspect it's the / thats doing it. Most browsers will automatically add this onto the end of the site they're visiting automatically. If you then add one aswell in the redirection header it may cause problems.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Apparently you're on a 'nix machine, so here's the scoop. The single slash / means' the root of the drive'. A dot slash, ./ means 'this directory', a double dot slash ../ means 'one directory up'. So if you use ./index.php, which I do a lot, you should be OK.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by DrDOS View Post
    Apparently you're on a 'nix machine, so here's the scoop. The single slash / means' the root of the drive'. A dot slash, ./ means 'this directory', a double dot slash ../ means 'one directory up'. So if you use ./index.php, which I do a lot, you should be OK.
    Yeah but that only applies to the file system DrDOS. This is a header command telling the BROWSER to visit a URL.

    IF the browser is already at www.homepage.com/ and you issue a header redirect to /index.php it will become www.homepage.com//index.php

    See where I'm going here?
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #6
    Regular Coder
    Join Date
    Aug 2012
    Posts
    142
    Thanks
    39
    Thanked 3 Times in 3 Posts
    As has been said, if the php files are in the same directory just remove the /

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    This is what I'm trying to explain here. If I type in a domain name like this:



    The browser will automatically append a / to the end when you hit enter or click go:



    Now if you issue a header with a / at the front, that / may be added to the existing address / directory. In this case it would become www.codingforums.com//index.php (note the two /'s). This isn't always the case, some browsers cater for it, others don't. What I'm saying is get rid of the / in the header call and see what happens.

    Thats what I am trying to explain here for those who don't see it.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •