PHP redirect

Discussion in 'PHP' started by sg552, Sep 21, 2008.

  1. #1
    Hi,

    I don't know if this is the correct title, please accept my apology.

    I have an index.php (main page) and content.php (my content) page. If visitor visiting my website, when they return they simply click on the url bar and go to the content.php bypassing index.php

    My question is how to block user from directly viewing my content at content.php and redirect them to index.php. Only after they click a link on index.php they will be redirect to content.php. eg: at index.php: click here to view content and they will be redirect to content.php

    So I try with sessions:

    Index.php (at the top)

    session_start(); $_SESSION["first_time"] = 1;
    PHP:
    Content.php (at the top, before all code)

    if($_SESSION["first_time"] != 1){    header("Location: index.php");}
    
    PHP:
    The problem is even after my first_time = 1 my content.php keep redirecting me to index.php :confused: Why is that?

    Any idea ?? Thanks for any help
    :)
     
    sg552, Sep 21, 2008 IP
  2. hamidof

    hamidof Peon

    Messages:
    619
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put a
    
    session_start();
    
    PHP:
    On top of your content.php too, before you chech for the variable ;)
     
    hamidof, Sep 21, 2008 IP
    sg552 likes this.
  3. sg552

    sg552 Peon

    Messages:
    187
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    wow I don't know I'm so stupid :eek:
    Thanks + rep added

    :)
     
    sg552, Sep 21, 2008 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Though that SOUNDS like a splash page - if your index doesn't actually have the content people actually want to get to, why the devil have it as a separate file?
     
    deathshadow, Sep 21, 2008 IP