Jump to content

Problem Is Session Command


Recommended Posts

when i execute code on my localhost and on 000webhost then it works fine but shows error on this host .

my php file's php code is this

 

<?php
// define variables and set to empty values
  $email = $password = "";
 $errors = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
       $con=mysqli_connect("localhost","deep958","<removed>");
  mysqli_select_db($con,"deep958_togetherwe");
  
  
  
  if (empty($_POST["email"])) {
    $errors['email']  = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
          $errors['email'] = "Invalid email format"; 
    }
else{
$a="select * from signup where email= '$email'";
   $aresult=mysqli_query($con,$a);
   $anum=mysqli_num_rows($aresult);
 
$b="select * from login where email= '$email'";
$bresult=mysqli_query($con,$;
$bnum=mysqli_num_rows($bresult);
 
if($anum==1) {$errors['email'] = "This email is not verified.Click <a href='\New folder\confirmation.php'>here</a> to verify it.";}
elseif($bnum==0) {$errors['email'] = "This email doesn't exist. Plz click <a href='\New folder\signup.php'>here</a> to sign up";}
 
 
}
 
  }
 
 
 
   if (empty($_POST["password"])) {
    $errors['password']  = "Password is required";
  } else {
    $password = $_POST["password"];
    // check if password is well-formed
     if (!preg_match_all('$\S*(?=\S{6,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$', $password)){
          $errors['password'] = "Invalid password"; 
    }
else{
    $row=mysqli_fetch_array($bresult);
$bpassword=$row['password'];
    if($password != $bpassword)
$errors['password']= "password is incoreecrt";
}
  }
  
 
 
  
    
   if(count($errors)==0)
{ session_start();
      $_SESSION['user']="$email";
 header("Location: /public_html/New folder/videos.php");
 exit();
}
  
  
  
}
 
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
 
 
 
 
?>

 

 

and errors that it is showing is in the image

Edited by Krydos
Removed password
  • Like 1
Link to comment
Share on other sites

You didn't post the whole file... Here's the missing beginning of the file:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Together We</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 <link href="https://fonts.googleapis.com/css?family=Open+Sans:400i,600i" rel="stylesheet">


  <link rel="stylesheet" type="text/css" href="lstylesheet.css">

  <style>
.error {color: #FF0000;}
</style>


</head>

<body id="myPage">



<?php
You obviously have html before any of the php code you posted. You're going to get that error if you use any of the session or header commands after already posting html to the page.
  • Like 1
Link to comment
Share on other sites

Create the session at the start of your file like everyone else does, then populate its values only if the conditions are met.

 

Generally when sessions are used they're started in every file, every time, right near the top (often the command itself will be in an include file).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...