Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP session is working on localhost but not on actual server

Tags:

html

php

i'm having trouble to pass session variable to another page. It is working on localhost but not on server. I would want to pass $_SESSION['user_check'] to editpasswordsignup.php but whenever i click submit, $_SESSION['user_check'] is empty.

This is loginsignup.php

<?php

include('db.php');

session_start(); 

?>

<div id="wrapper">
<div id="wrapper-bg">
<div id="wrapper-bgtop">
  <div class="container" id="header">
    <div class="container" id="logo">
      <h1><a href="indexhomepage.php"></a></h1>
    </div>
  </div>

  <div class="container" id="page">
    <div id="loginbox">
        <form action="" class="formbox" method="post">
        <label>Email Address:</label> 
        <input class="box1" name="email" type="text"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <label>Password:</label> 
        <input class="box2" name="password" type="password"> 
        <a class="myButton1" href="forgetpassword.php">Forgot Password</a><br>
        <input class="submit5" name="submit" type="submit" value="Login"> 
        <a href="signup.php" id="myButton2">Create Account</a>
        </form>

            <?php

            if (isset($_POST['submit']))
            {
            $email =   ($_POST["email"]);
            $password =($_POST["password"]);

            $_SESSION['user_check'] = $_POST["email"];

            $sql = mysql_query ("SELECT * FROM user WHERE email = '$email'  ");

            $row = mysql_fetch_array($sql);

            $drawemail = $row['email'];

            $drawpassword = $row['password'];   

            if (($drawemail == $email ) && ($drawpassword == $password ))

            {
            ?>
            <script>window.location = "../wordsignup.php";</script>;

            <?php
            }

            else 
            {
            echo "wrong password or username";
            }
            }

            ?>

    </div>
  </div>

  <div class="container" id="footer-content-bg">
    <div id="footer-content">
      <ul>
        <li class="footer1">
          <a href="aboutus.php">About us</a>
        </li>

        <li>
          <a href="termandcon.php">Term and Conditions</a>
        </li>

        <li>
          <a href="privacyadvertising.php">Privacy Advertising</a>
        </li>

        <li>
          <a href="policy.php">Policy</a>
        </li>

        <li>
          <a href="userargeement.php">User Agreement</a>
        </li>
      </ul><br>

      <div id="copyright">
        © . All Rights Reserved.
      </div>
    </div>
  </div>
</div>

This is editpasswordsignup.php

  <?php 

  include('db.php');

  session_start();

  $user_check = $_SESSION['user_check'];

  ?>

 <div id="wrapper">
<div id="wrapper-bg">
<div id="wrapper-bgtop">
  <div class="container" id="header">
    <div class="container" id="logo">
      <h1><a href="indexhomepage.php"></a></h1>
    </div>
  </div>

  <div class="container" id="page">
    <div id="forgetpassword">
      <div style="font-size:20px; color:#000080; font-weight:bold; border-width:1px; border-style:none; width:600px; margin:10px 0px 0px 175px;">
        Edit Password
      </div>

      <div style="font-size:16px;border-style:none; width:560px; margin:20px 0px 10px 175px; font-weight:bold;">
        Please enter your old password below and we will send you your password.
      </div>

      <div id="forgetpasswordbox">
        <form class="forgetpassword" method="post">
        Please enter your old password<br>
        <input class="oldpassword" name="oldpassword" type="password"><br><br>
        Please enter your new password<br>
        <input class="newpassword" name="newpassword" type="password"><br><br>
        Please re-enter new password<br>
        <input class="confirmpassword" name="confirmpassword" type="password"><br><br>     
        <input name="submit" type="submit" value="Send" class="send">
        </form>

      </div>
    </div>
  </div>

  <div class="container" id="footer-content-bg">
    <div id="footer-content">
      <ul>
        <li class="footer1">
          <a href="aboutus.php">About Us</a>
        </li>

        <li>
          <a href="termandcon.php">Term and Conditions</a>
        </li>

        <li>
          <a href="privacyadvertising.php">Privacy Advertising</a>
        </li>

        <li>
          <a href="policy.php">Policy</a>
        </li>

        <li>
          <a href="userargeement.php">User Agreement</a>
        </li>
      </ul><br>

      <div id="copyright">
        © . All Rights Reserved.
      </div>
    </div>
  </div>
   </div>
  </div>
  </div>

    <?php       
    if (isset($_POST['submit']))
    {               
    $oldpassword = $_POST['oldpassword'];
    $newpassword = $_POST['newpassword']; 
    $confirmpassword = $_POST['confirmpassword']; 

    $sql = mysql_query (("SELECT * FROM user WHERE email='user_check' AND password='$oldpassword' "),$conn);

    $row = mysql_fetch_array($sql);
    $email = $row['email'];
    $selectpassword = $row['password'];

    if ($oldpassword == "")
    {

    echo '<script language="javascript">';
    echo 'alert("pls enter your oldpassword")';
    echo '</script>';
    exit;
    }

    if($newpassword=="")
    {
    echo '<script language="javascript">';
    echo 'alert("pls enter your newpassword")';
    echo '</script>';
    exit;

    }

    if($confirmpassword=="")
    {
    echo '<script language="javascript">';
    echo 'alert("pls enter your confrimpassword")';
    echo '</script>';
    exit;

    }       

    if (($oldpassword) != ($selectpassword)) 
    {
    echo '<script language="javascript">';
    echo 'alert("No user exists with this password  '.$selectpassword.' ")';
    echo '</script>';
    exit;
    }

    if ($newpassword == ($confirmpassword))
    {   
    mysql_query("UPDATE user SET password = '".$newpassword."' WHERE email='".$email."'");

    $message = "Your password ".$newpassword." and click the link uploadsignup.php to upload your photo";   

    mail($email, "Change Password", $message);
    ?>

    <script>

    alert("Password Successfully change...!!!!\nClick OK to upload photo\nNewpassword will send to your email address");
    window.location="uploadsignup.php";

   </script>   


    <?php
    }
    else 
    {
    echo '<script language="javascript">';
    echo 'alert("new password does not match")';
    echo '</script>';

    }
    }

    ?>
like image 674
user3379528 Avatar asked Sep 14 '25 03:09

user3379528


1 Answers

As you said it's working on localhost and not on the particular server, you might have a different settings in php.ini. Check out http://php.net/manual/en/session.configuration.php

like image 181
tomik Avatar answered Sep 16 '25 16:09

tomik