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
    139
    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
    721
    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,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,994
    Thanks
    15
    Thanked 233 Times in 233 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,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    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?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #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,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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