Skip to content

Instantly share code, notes, and snippets.

@feulf
Last active July 27, 2022 11:15
Show Gist options
  • Select an option

  • Save feulf/4587709 to your computer and use it in GitHub Desktop.

Select an option

Save feulf/4587709 to your computer and use it in GitHub Desktop.

Revisions

  1. feulf revised this gist Jan 21, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,10 @@ a simple idea is to force the session_id between the domains with an ajax call o
    The concept is simple, you have [A,B,C] domains, where you create a script *sid.php*:

    ``` php

    <?php session_id( $_GET['sid'] );

    and a script *sid_update.php* that you have to place inside the PHP code of the front controller:
    ```

    and a script *sid_update.php* that you have to place inside the PHP code of the front controller:
    ``` php

    <?php
    @@ -31,6 +30,7 @@ and a script *sid_update.php* that you have to place inside the PHP code of the
    }
    $_SESSION['sid_updated'] = true;
    }
    ```

    An AJAX call it could be better then the iframe, up to you to implement a better solution.

  2. feulf revised this gist Jan 21, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,8 @@ a simple idea is to force the session_id between the domains with an ajax call o
    The concept is simple, you have [A,B,C] domains, where you create a script *sid.php*:

    ``` php
    <?php session_id( $_GET['sid'] );

    <?php session_id( $_GET['sid'] );

    and a script *sid_update.php* that you have to place inside the PHP code of the front controller:

  3. feulf revised this gist Jan 21, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,12 @@
    a simple idea is to force the session_id between the domains with an ajax call or an hidden iframe.

    The concept is simple, you have [A,B,C] domains, where you create a script *sid.php*:

    ``` php
    <?php session_id( $_GET['sid'] );

    and a script *sid_update.php* that you have to place inside the PHP code of the front controller:

    ``` php

    <?php
  4. feulf revised this gist Jan 21, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    a simple idea is to force the session_id between the domains with an ajax call or an hidden iframe.

    The concept is simple, you have [A,B,C] domains, where you create a script *sid.php*:
    ``` php
    ``` php
    <?php session_id( $_GET['sid'] );

    and a script *sid_update.php* that you have to place inside the PHP code of the front controller:
    ``` php

    <?php
    <?php
    // start the session
    session_start();
    // get the session id
  5. feulf revised this gist Jan 21, 2013. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,10 @@
    a simple idea is to force the session_id between the domains with an ajax call or an hidden iframe.

    The concept is simple:
    - you have [A,B,C] domains
    The concept is simple, you have [A,B,C] domains, where you create a script *sid.php*:
    ``` php
    <?php session_id( $_GET['sid'] );

    - create a script sid.php in all of them, to force the SID
    <?php session_id( $_GET['sid'] );
    - create a script to update the sid in the other domains, and place it in your common PHP code:
    and a script *sid_update.php* that you have to place inside the PHP code of the front controller:
    ``` php

    <?php
    @@ -31,4 +29,7 @@ The concept is simple:
    $_SESSION['sid_updated'] = true;
    }

    A good alternative is to use AJAX instead of the iframe, up to you to find out a better solution to implement this idea.
    An AJAX call it could be better then the iframe, up to you to implement a better solution.

    ### Note
    This solution is not safe! If you have a good solution to improve the security of it, please update this GIST.
  6. feulf revised this gist Jan 21, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,4 @@ The concept is simple:
    $_SESSION['sid_updated'] = true;
    }

    ```

    A good alternative is to use AJAX instead of the iframe, up to you to find out a better solution to implement this idea.
  7. feulf created this gist Jan 21, 2013.
    36 changes: 36 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    a simple idea is to force the session_id between the domains with an ajax call or an hidden iframe.

    The concept is simple:
    - you have [A,B,C] domains

    - create a script sid.php in all of them, to force the SID
    <?php session_id( $_GET['sid'] );
    - create a script to update the sid in the other domains, and place it in your common PHP code:
    ``` php
    <?php
    // start the session
    session_start();
    // get the session id
    $sid = session_id();
    // url of all domains
    $domains = ['A','B','C'];
    // this domain, you may want to set this manually
    $url = $_SERVER['SERVER_NAME'];
    // execute this script only once
    if( isset($_SESSION['sid_updated']) && true === $_SESSION['sid_updated'] ){
    foreach( $domains as $domain ){
    // update all domains except the one we are now
    if( $domain != $url ){
    // print an hidden iframe
    echo "<iframe src=\"{$domain}?sid={$sid}\" style="position:absolute;top:-1000;"></script>";
    }
    }
    $_SESSION['sid_updated'] = true;
    }

    ```

    A good alternative is to use AJAX instead of the iframe, up to you to find out a better solution to implement this idea.