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 12 of 12
  1. #1
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts

    Question Getting the referring page in IE

    I have to make a workaround for some code that basically means I need to somehow track what page has just clicked on a link to my current code. Then deal with that accordingly.

    HTTP_REFERER would be perfect if the target machine wasn't running IE (which doesn't like to display this information!)

    All I need is the previous pages name, or some unique way of identifying it without passing variables through.

    I had toyed with the idea of using sessions, but I don't know the best way to randomly allocate and update them as a user could click on several candidate pages before clicking on the link to the code with the tracker.

    Any help would be greatly appreciated.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    HTTP_REFERER is not reliable as for example firewalls can prevent that kind of information from being sent. You'd need to use Session instead.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    It is being deployed in an enclosed environment where we can control that stuff, but that is academic since IE doesn't want to play ball!

    How do I go about setting up sessions to work differently from most?

    The way I see it I want one session variable, which gets updated dependent on the page you are on and can be easily tracked so I know how to act when the session variable appears.

    Any ideas?

  • #4
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Ha, turns out I was being an idiot, I know how to handle sessions fine - I was over complicating what they needed to do in my head!

    [edit]

    Actually no, could someone give me some pointers? I have set up my session variable but it doesn't wanna pass itself onto my page that is waiting for it.
    Last edited by tosbourn; 08-28-2008 at 04:07 PM. Reason: It would appear I am being a double idiot.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Guess you missed to call the session_start() in the second page.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by abduraooft View Post
    Guess you missed to call the session_start() in the second page.
    Nope, it is there in both.

    A page can set a session, and once it is set it can view it, but it doesn't want to carry across to the next page.

  • #7
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Here is the code... (just a test obviously)

    Page one... (accessed first)

    PHP Code:
    session_start();

    $_SESSION['refpage'] = "home.php"
    Page two...(the thing that should handle the sessions)

    PHP Code:
    <?php
    session_start
    ();
    if(isset(
    $_SESSION['refpage'])){
    echo 
    $_SESSION['refpage']; }
    else{
    echo 
    "WHY GOD DAMN YOU, WHY?!?!?!";
    $_SESSION['refpage']= "tester.php";
    }
    ?>
    The first time around the string gets printed out, the second time around (and any other times even going back to the first page) it will say tester.php (I want to to say home.php)
    Last edited by tosbourn; 08-28-2008 at 04:23 PM.

  • #8
    New Coder
    Join Date
    Apr 2005
    Posts
    51
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I don't have that problem at all; it acts just as expected. Unless I move the ="tester.php" code outside of the else loop, it never gets executed, and if it does, resetting the value to "home.php", well, resets it.

    I'd take a look at your cookie settings. Make sure that above is really *all* you've got in your test pages, and try different browsers.

  • #9
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Page two is 100% just that, page 1 has a load more stuff on it.

    Basically this is a project I have been assigned that someone else had completed but not properly - I have to fix it up (including making it IE proof).

  • #10
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Here is sessions.php - one of the things called on that first page before I declare my session. This is the only thing that I would think would come close to affecting sessions.

    PHP Code:
    <?php 
    require_once("dbfactory.php");
    define("STAMP_FORM""YmdHis"); // Default timestamp format.

    function sess_connectDB(){
        
    /*
            function to connect to the backend database with local db defined parameters.
        */
        
    try  {
            
    $dbh = new DBFactory(); 
            return 
    $dbh;
        }
        catch(
    ADODB_Exception $e){
            
    header("Location: nodb.php");
            exit;
        }
    }
    function 
    sopen($save_path$session_name){    
        
    /*
            No need to do anything here.
        */
        
    return true;
    }
    function 
    sclose(){
        
    /*
            No need to do anything here.
        */
        
    return true;
    }
    function 
    sread($id){
        
    /*
            Reads session data from the database
        */
        
    $dbh sess_connectDB();
        
    $sql "SELECT * FROM `TS::Sessions` WHERE sid='$id'";
        
    $dbh->SetFetchMode("ASSOC");
        
    $rs $dbh->Execute($sql);
        
    $row $rs[0];//->fields;    
        //print_r($row);
        
    return $row['sdata'];
    }
    function 
    swrite($id$sess_data) {
        
    /*
            Writes session data to the database
        */
        
    try {
            
    $dbh sess_connectDB();
            
    $clean_data $dbh->qstr($sess_data);
            
    $timestamp date(STAMP_FORM);
            
    $sql "DELETE FROM `TS::Sessions` WHERE sid='$id'";
            
    $dbh->Execute($sql);
            
    $sql "INSERT INTO `TS::Sessions` (sid, sdata, modtime) VALUES('$id', $clean_data, '$timestamp')";
            
    $dbh->Execute($sql);
            
    //printr($sql);
        
    }
        catch (
    Exception $e){
            
    var_dump($e);
        }
    }
    function 
    sdestroy($id){
        
    /*
            We are finished with the db, so wipe the session
        */
        
    $dbh sess_connectDB();
        
    $dbh->Execute("DELETE FROM `TS::Sessions` WHERE sid='$id'");
        
    $_SESSION= array();
    }
    function 
    s_gc($maxlifetime){
        
    /*
            Garbaage collection.
        */
        
    $dbh sess_connectDB();
        
    $ts time() - $maxlifetime;
        
    $timestamp date(STAMP_FORM$ts);
        
    $dbh->Execute("DELETE FROM `TS::Sessions` WHERE modtime < '$timestamp'");
    }

    // Make PHP use *our* session handling.
    if (session_set_save_handler
      
    "sopen"
      
    "sclose"
      
    "sread"
      
    "swrite"
      
    "sdestroy"
      
    "s_gc" 
    )===false){
        die(
    "Sessions are broken");
    }

    // As this will be included in any page that wants session access, we might as well start it here.
    session_start();
    But I can't see anything in it that would stop you making your own sessions (he has used them in the code and I am assuming they are doing their job!!)

    Any help would be greatly appreciated!

  • #11
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    The original coder has replaced default session storage with their own database solution, this means that any session data created in the first page will not be stored in the normal PHP session location and hence will not be available to your second page _unless_ it also includes this code and hence shares the replacement session storage.

    The solution is either to comment out the replacement session handling throughout (but there may be a very good reason why it does this) or to include the same session.php in your second (test) page and anywhere else that you want to handle session data.

    HTH,

    Dai

  • Users who have thanked DaiWelsh for this post:

    tosbourn (08-29-2008)

  • #12
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    I had just stuck the sessions thing in about 15 minutes before reading this! Worked a treat.

    Thanks so much!


  •  

    Tags for this Thread

    Posting Permissions

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