#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0

    Session_start() in included/loaded files/pages


    Hi,

    I remarked I can't put the following code in pages/files I include (php) or load (ajax):
    PHP Code:
    <?php 
    session_start
    (); 
    if(!
    session_is_registered("number")) {
    header("location:shoot_nr.php"); 

    ?>
    That means everybody can access those files/pages without first selecting a number if they know the direct url.

    Why?

    Thx n advance.
    kr,
    C.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    that "session_is_registered" is ancient, where do you even got it from? You're also missing an "exit;" after the redirect, so the PHP code will keep running.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    that "session_is_registered" is ancient, where do you even got it from? You're also missing an "exit;" after the redirect, so the PHP code will keep running.
    But it works, at least for the head page.
    In the head page I include one page and I have one link to load another page.

    I know it's ancient. PHP manual says:
    This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.
    I will try:
    PHP Code:
    session_start();
    $_SESSION['number'];
    if (isset(
    $_SESSION['number']){ //do.. } 
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0

    Unhappy


    It's not working.
    Head page:
    PHP Code:
    <?php 
    session_start
    (); 
    if (!isset(
    $_SESSION['number'])) { 
    header("Location: shoot_nr.php"); 

    ?>
    //... html page
    Included in head page:
    PHP Code:
    if (!isset($_SESSION['number'])) { 
    header("Location: shoot_nr.php"); 

    Loaded in head page:
    PHP Code:
    session_start(); 
    if (!isset(
    $_SESSION['number'])) { 
    header("Location: shoot_nr.php"); 

    Kill session page:
    PHP Code:
    <?php

    session_destroy
    ();
    session_unset();
    header("Location: shoot_nr.php");
    ?>
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    28
    Rep Power
    0
    It works now. I forgot to start the session in kill.php page.
    Thx.

IMN logo majestic logo threadwatch logo seochat tools logo