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.

problem parameter to session

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

  1. #1
    i wrote php script ,problem to transfer values of level and sum to script End_session.php
    can you help me ?
    <?php
    
        $s_user="";
    
        session_start();
        if(isset($_SESSION["user"])){
            global $s_user;
            $s_user=$_SESSION["user"];
            echo $s_user;
        };
    ?>
    
    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>Game</title>
        <link rel="stylesheet" href="styles.css" type="text/css">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $("td").click(function(){
                    boxer(this);
                })
            });
    
            var sum = 0;
            var random;
            var level = 1;
    
    
            function boxer(obj){
                var singleValue = obj.innerHTML;
                if(obj.style.backgroundColor != "red") {
                     sum = Number(sum) + Number(singleValue);
                     obj.style.backgroundColor = "red";
                     document.getElementById("sum").innerHTML = sum;
                    }
                else{
                    obj.style.backgroundColor = "greenyellow";
                    sum = Number(sum) - Number(singleValue);
                    document.getElementById("sum").innerHTML = sum;
                }
                if(sum==random){
                    alert("You won");
                    level++;
                    if(level==2){
                        document.getElementById("box4").className = "show";
                        numGen();
                        sum = 0;
                        document.getElementById("sum").innerHTML = sum;
                    }
                    if(level==3){
                        document.getElementById("box5").className = "show";
                        numGen();
                        sum = 0;
                        document.getElementById("sum").innerHTML = sum;
                    }
                    if(level==4){
                        document.getElementById("box6").className = "show";
                        numGen();
                        sum = 0;
                        document.getElementById("sum").innerHTML = sum;
                    }
                    if(level==5){
                        document.getElementById("box7").className = "show";
                        numGen();
                        sum = 0;
                        document.getElementById("sum").innerHTML = sum;
                    }
                    if(level==6){
                        document.getElementsByTagName("body")[0].innerHTML = "Congrats! You are an epic player!";
                    }
    
                }
    
    
            }
    
            function numGen(){
                random = Number(Math.floor((Math.random() * 500) + 100));
    
                document.getElementById("gen").innerHTML = random;
    
                myArr = [];
    
                if(level==1){
                    myArr.push(random/2);
                    myArr.push(random/2);
                    myArr.push(random-50);
                }
    
                if(level==2){
                    myArr.push(random/2-30);
                    myArr.push(random-70);
                    myArr.push(random/4+10);
                    myArr.push(random/4+20);
                }
    
                if(level==3){
                    myArr.push(random/2-60);
                    myArr.push(random+45);
                    myArr.push(random/4+25);
                    myArr.push(random/4+35);
                    myArr.push(random-20);
                }
    
                if(level==4){
                    myArr.push(random/2-80);
                    myArr.push(random+85);
                    myArr.push(random/8+15);
                    myArr.push(random/8+35);
                    myArr.push(random/8+5);
                    myArr.push(random/8+25);
                }
    
                if(level==5){
                    myArr.push(random/2-85);
                    myArr.push(random+85);
                    myArr.push(random/8+35);
                    myArr.push(random/8+25);
                    myArr.push(random/8+15);
                    myArr.push(random/8+10);
                    myArr.push(random-125)
                }
    
                shuffle(myArr);
    
                function shuffle(o){
                    for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
                    return o;
                }
    
    
    
    
                document.getElementById("box1").innerHTML = myArr[0];
                document.getElementById("box2").innerHTML = myArr[1];
                document.getElementById("box3").innerHTML = myArr[2];
                document.getElementById("box4").innerHTML = myArr[3];
                document.getElementById("box5").innerHTML = myArr[4];;
                document.getElementById("box6").innerHTML = myArr[5];;
                document.getElementById("box7").innerHTML = myArr[6];;
    
                document.getElementById("box1").style.backgroundColor = "greenyellow";
                document.getElementById("box2").style.backgroundColor = "greenyellow";
                document.getElementById("box3").style.backgroundColor = "greenyellow";
                document.getElementById("box4").style.backgroundColor = "greenyellow";
                document.getElementById("box5").style.backgroundColor = "greenyellow";
                document.getElementById("box6").style.backgroundColor = "greenyellow";
                document.getElementById("box7").style.backgroundColor = "greenyellow";
    
            }
        </script>
    </head>
    <body onload=numGen()>
    
    <div id="gen"></div>
    <div id="sum">0</div>
    
    <table align="center">
        <tr>
            <td id="box1"></td>
            <td id="box2"></td>
            <td id="box3"></td>
            <td id="box4" class="hide"></td>
            <td id="box5" class="hide"></td>
            <td id="box6" class="hide"></td>
            <td id="box7" class="hide"></td>
        </tr>
    </table>
    <div>
         <form method="post" action="End_session.php">
           
            <input type="hidden" id="maxnum" name="maxNum" value="0"/>
            <input type="hidden" id="lev" name="level" value="0"/><br><br><br><br>
            <button type="submit">Finish</button>
        </form>
    </div>
        <p>
        <?php
        echo $GLOBALS["s_user"];
        ?>
    </p>
        </body>
    </html>
    PHP:

    SEMrush
     
    ssimon171078, May 22, 2015 IP
    SEMrush