1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

link problem

Discussion in 'PHP' started by ssimon171078, May 20, 2015.

  1. #1
    i wrote php script +js script problem is when game finished to go to end_session.php:
    my php script :game.php :
     <?php
    
        $s_user="";
    
        session_start();
        if(isset($_SESSION["user"])){
            global $s_user;
            $s_user=$_SESSION["user"];
            echo $s_user;
        };
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <title>Playing with adding numbers</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
       
        <script type="text/javascript" src="game.js"></script>
        <link rel="stylesheet" href="style.css">
    
    </head>
    <body >
    <p id="text">Add three numbers that their outcome will be equal to 100 !!!!</p>
    
    <div id="aa">
        <p>10</p>
        <p>40</p>
        <p>50</p>
        <p>300</p>
        <p>100</p>
        <p>25</p>
        <p>7</p>
        <p>5</p>
    
    </div>
    
    </body>
    </html>
    PHP:
    js script : game.js :
    /**
    * Created by User on 01.11.14.
    */
    var y=0;
    var result = 0;
    var  flagClick=3;
    var flagLevel=1;
    /*======================================*/
    $(document).ready(function(){
    
    
        $("p").click(function(){
            $(this).css({"background-color": "green"});
    
            var t= $(this).text();
            sum(t);
        });
        for(i=1;i<=8;i++,y++){
           
            var number1=(Math.floor(Math.random() * 50) + 1);
            var number2=(Math.floor(Math.random() * 25) + 1);
            var number3= 100-(number1+number2);
                 var num=new Array(number1,number2,number3);
            $("p").eq(i).text(num[y]);
            if(i<=4){
                $("p").eq(i).css("display","block");
            }
        }
    
    });
    /*  -----  eta functia sumiruet nash resultat */
    function sum(num){
        var res = parseInt(num);
        if(flagLevel==1){
            if( flagClick==0){
                alert("Ti praigral");
               window.open("game.php","_parent");
    
            }else{
                flagClick--;
                result = eval (result +res);
                if(result==100){
                    alert("Congratulations, you got the correct amount !!!");
                    flagLevel=2;
                    flagClick=3;
                    result=0;
                    /*---- zagrujaem document i atabrajaem ishi dve(total=6) knopchi vmeste s verhnii p---*/
                    $(document).ready(function(){
                        $("p#text").text("Add three numbers that their outcome will be equal to 450 !!!!");
                        $("div p").css({"margin-top": "1em","margin-left": "1.5em"});
                        $("p").css({"background-color": "red"});
                        $("p#text").css({"background-color": "chartreuse", "border": "0.2em solid red" });
                        $("p").eq(5).css("display","block");
                        $("p").eq(6).css("display","block");
                    });
                }else if(result>=100){
                    alert("Summa nevernaya");
                    window.open("game.php","_parent");
                }
            }
        }else if(flagLevel==2){
            if( flagClick==0){
                alert("Ti praigral");
                window.open("game.php","_parent");
            }else{
                flagClick--;
                result = eval (result +res);
                if(result==450){
                    alert("Congratulations, you got the correct amount !!!");
                    flagLevel=3;
                    flagClick=2;
                    result=1;
                    /*---- zagrujaem document i atabrajaem ishi dve(total=8) knopchi vmeste s verhnii p---*/
                    $(document).ready(function(){
                        $("p#text").text("Two numbers that multiply their result to be in 2500 !!!! ");
                        $("div p").css({"margin-top": "0.8em","margin-left": "0.8em"});
                        $("p").css({"background-color": "red"});
                        $("p#text").css({"bakground-color":"aqya","border": "0.2em solid red"});
                        $("p").eq(7).css("display","block");
                        $("p").eq(8).css("display","block");
    
                    });
                }else if(result>=450){
                    alert("Summa nevernaya");
                    window.open("game.php","_parent");
                }
            }
        }else if(flagLevel==3){
            if( flagClick==0){
                alert("Ti praigral");
                window.open("game.php","_parent");
            }else{
                flagClick--;
                result = (result*res);
                if(result==2500){
                    $(document).ready(function(){
                        $("html").html('<!DOCTYPE html>' +
                            ' <html> ' +
                            ' <head>' +
                            ' <title>Playing with adding numbers</title>' +
                            ' <link rel="stylesheet" href="style.css">'+
                            '</head>' +
                            '<body bgcolor="#56aaff"!important> ' +
                            '<p id="finish"> Congratulations !!! You have reached the end of the game !!!</p>' +
                            '</body>' +
                            '</html>');
                    window.open("end_session.php","_parent");
                    });
                }else if(result>=2500){
                    alert("Summa nevernaya");
                    window.open("game.php","_parent");
                }
            }
        }
    }
    
    Code (JavaScript):

     
    ssimon171078, May 20, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Don't use window open, just call the file via Ajax, and tell it to end the session.
     
    PoPSiCLe, May 20, 2015 IP
  3. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #3
    Why are you opening so many windows? You might consider using window.location.href to redirect pages instead? Or just showing a popup with js as a div. Or do what @PoPSiCLe said...

    
    request = $.ajax({
        url:"end_session.php",
        type:"post"
    });
    
    PHP:
     
    Anveto, May 20, 2015 IP