0

I am making a portal of games where different games are showing on index page.

There are two procedures of playing games:

  1. When user opens the index page and clicks on any game, if he is not logged-in already, then login form is showing on play.php; when user logs in then game will start

  2. When user opens the index page and if he/she is already logged-in then login form will not appear. He can directly play a game.

Issue is that when a game is running on play.php, after playing user clicks back button in browser to return to the index page. But browser is showing play.php first and user has to click back button again to see index.php

Is there any way when click on back button then directly show index.php not show play.php again

index.php

<?php
   $i=0;
   $Res_games=mysqli_query($con, "SELECT * from tbl_games where 
   category_id=".$Row_Cat['id']);
   while($Row_games = mysqli_fetch_array($Res_games)){
       $img = $Row_games['icon_large'];
       $game_url = $Row_games['url'];
       $game_name = $Row_games['title'];
       $formid=$Row_Cat['prefix'].$i;
?>
<div class="productCarousel-slide">
   <article class="card ">
      <figure class="card-figure">
         <form id="<?php echo $formid; ?>" method="post" action="play.php">
            <input type="hidden" name="url" value="<?php echo $game_url; ?>">
         </form>    
         <a href="#" onclick="document.forms['<?php echo $formid; ?>'].submit();" title="<?php echo $game_name1; ?>">
            <img class="card-image" src="<?php echo $img; ?>" alt="<?php echo $game_name;?>" title="<?php echo $game_name;?>">
         </a>
         <figcaption class="card-figcaption">
         <div class="card-figcaption-body">
            <div class="card-buttons">
            </div>

            <div class="card-buttons card-buttons--alt">

            </div>
        </div>
    </figcaption>
</figure>
<div class="card-body">
    <h4 class="card-title" style="text-align: center !important;">
        <a href="<?php echo  $game_url;?>"><?php echo $game_name;?></a>
    </h4>
  </div>
  </article>
  </div>

<?php 
  $i++;
   }    
 ?>

Play.php

<?php 
include('assets/db_connect.php');
$url1 = urlencode($_REQUEST['url']);

header("Cache-Control: no cache");
session_cache_limiter("private_no_expire");

 if(isset($_SESSION['loginid'])){ 
 ?>
 <html>
 <head>
<style>
.resp-iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}}
</style>
</head>
<body>
<div class="resp-container">
<iframe class="resp-iframe" src="page1.php?url=<?php echo $url1;?>" gesture="media"  allow="encrypted-media" allowfullscreen></iframe>
</div>
</body>
</html>
<?php } else { ?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="icon" href="assets/images/blue_logo.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="assets/vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="assets/fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="assets/fonts/iconic/css/material-design-iconic-font.min.css">
<link rel="stylesheet" type="text/css" href="assets/vendor/animate/animate.css">
<link rel="stylesheet" type="text/css" href="assets/vendor/css-hamburgers/hamburgers.min.css">
<link rel="stylesheet" type="text/css" href="assets/vendor/animsition/css/animsition.min.css">
<link rel="stylesheet" type="text/css" href="assets/vendor/select2/select2.min.css">
<link rel="stylesheet" type="text/css" href="assets/vendor/daterangepicker/daterangepicker.css">
<link rel="stylesheet" type="text/css" href="assets/css/util.css">
<link rel="stylesheet" type="text/css" href="assets/css/main.css">
 </head>
 <body>
 <?php 
 if($_SESSION['loginid']!='' && !isset($_REQUEST['login'])){ ?>
<script>location.replace("index.php");</script>
<?php   
 }
if(isset($_POST['login'])){
            $msisdn = $_REQUEST['msisdn'];
                        //Check Mobile No. 
           $chk_Zero= substr($msisdn, 0, 1);
           $chk_92= substr($msisdn, 0, 3);
           if ($chk_Zero==0){
                $msisdn = substr($msisdn, 1);
                $msisdn = '92'.$msisdn;
           }
           if($chk_92=='923'){
                $msisdn = $msisdn;
           }
            $cdate = date("Y-m-d H:i:s");
            $rows=0;
            $SQL1="SELECT * FROM tbl_useraccount where msisdn='$msisdn' and status=1";
            $result = mysqli_query($con,$SQL1);
            $GetRows=mysqli_fetch_array($result);
            if($GetRows['msisdn']==$msisdn)
            {
                $ID=$GetRows['id'];

            //Store OTP
            /*  $otp= rand(1000,9999);                  
                $OTP_Insert=mysqli_query($con,"Update tbl_usersotp set otp='$otp', modify_date='$cdate' where userid='$ID' and msisdn = '$msisdn' and sms_status=1");
                $Message="Dear User,\n\nYour Verification Code is $otp. \n\nTelenor Games";

                file_get_contents("http://115.186.146.246:13013/cgi-bin/sendsms?username=tester&password=foobar&to=".$msisdn."&text=".urlencode($Message));
            */

                $_SESSION['loginid']=$ID;                   
                $_SESSION['msisdn']=$msisdn;

                //Login Attempt Information
                    $userid=$ID;
                    $localIP = getHostByName(getHostName());
                    $server_ip=$_SERVER['REMOTE_ADDR'];
                    $session_id = session_id(); $_SESSION['session_id'] = $session_id;
            $CInsert=mysqli_query($con,"INSERT INTO tbl_login_attempt (userid, date_time, local_ip, server_ip, login_status, session_id) VALUES ('$userid', '$cdate', '$localIP', '$server_ip', '1', '$session_id')");
            if(isset($_REQUEST['game_url'])){ 
            ?>
            <form id="frm_url1" action="play.php" method="post">
                <input type="hidden" name="url" value="<?php echo $_REQUEST['game_url'];?>" /> 
            </form>
                <script type="text/javascript">
                    document.getElementById("frm_url1").submit();
                </script>

            <?php } ?>

<?php }else{$message = "<font color='#bb0000'>Invalid Mobile Number. Please re-enter the details and login again.</font>";}

}
?>

<div class="limiter">
    <div class="container-login100" style="background-color:#000000">
    <!-- background-image: url('assets/images/bg-01.jpg'); -->
        <div class="wrap-login100 p-l-55 p-r-55 p-t-65 p-b-54">
            <form class="login100-form validate-form" action="play.php" method="post" enctype="multipart/form-data">
<?php echo $message; ?>         

<input type="hidden" name="game_url" value="<?php echo urldecode($url1);?>" />
                <span class="login100-form-title p-b-49">
                    <img class="logo-responsive" src="assets/images/logo-white.png"/>Login
                </span>

                <div class="wrap-input100 validate-input m-b-23" data-validate = "Mobile Number is required">
                    <span class="label-input100">Mobile Number</span>
                    <input class="input100 allownumericwithoutdecimal" type="text" name="msisdn" placeholder="03XX1234567">
                    <span class="focus-input100" data-symbol="&#xf2cc;"></span>
                </div>

                <div class="container-login100-form-btn">
                    <div class="wrap-login100-form-btn">
                        <div class="login100-form-bgbtn"></div>
                        <button class="login100-form-btn" type="submit" name="login">
                            Login
                        </button>
                    </div>
                </div>
                <br><br><br>
                <!--<div class="txt1 text-center p-t-54 p-b-20">
                    <span>
                        Or Login Using
                    </span>
                </div>

                <div class="flex-c-m">
                    <a href="#" class="login100-social-item bg1">
                        <i class="fa fa-facebook"></i>
                    </a>

                </div>-->

                <div class="flex-col-c p-t-155">
                    <span class="txt1 p-b-17">
                        Not registered?
                    </span>

                    <a href="register.php" class="txt2">
                        Register
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>


<div id="dropDownSelect1"></div>

<script src="assets/vendor/jquery/jquery-3.2.1.min.js"></script>
<script src="assets/vendor/animsition/js/animsition.min.js"></script>
<script src="assets/vendor/bootstrap/js/popper.js"></script>
<script src="assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/vendor/select2/select2.min.js"></script>
<script src="assets/vendor/daterangepicker/moment.min.js"></script>
<script src="assets/vendor/daterangepicker/daterangepicker.js"></script>
<script src="assets/vendor/countdowntime/countdowntime.js"></script>
<script src="assets/js/main.js"></script>
<script>
$(".allownumericwithoutdecimal").on("keypress keyup blur",function (event) {    
       $(this).val($(this).val().replace(/[^\d].+/, ""));
        if ((event.which < 48 || event.which > 57)) {
            event.preventDefault();
        }
    });
</script>
</body>
</html>
Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
Hayam khan
  • 59
  • 7

0 Answers0