php session Code not Working on Live Server – error Fix

Spread the love

php session Code not Working on Live Server: Hello friends, those of us who are new to php, and using php are having some problems when we are building websites. One of the problems is that when we create the login page with our php code, after giving username and password in login, the php session does not start on our welcome page. This problem is happening to almost everyone now.

Also Read: Google Analytics api – Google Analytics how to add php website

Those who are expert programmers in php programming will not have this problem because they know the solution to this problem. Because they have face this problem before or not but because of their expertise they are able to solve that problem effortlessly.

Many people are trying to get php code to run on their html page. One thing to keep in mind is that php code will never work properly on html page.

Also Read: How to Create a Secure php Login Page with MySQL Database

Also Read: How to use md5 hash in php – what is hash?

In today’s article we will know that php session code does not work for some reason. In this article we will discuss why sessions do not start on the welcome page even after logging in. So don’t worry friends after reading this article I think you will not have any problem with this php session and you will get the solutions.

What is the php session?

In a word, a variable is where we store data on different pages for use. If we have created our website as an account system for users where the user can login to the account with his username and password. This session is started on all those websites. Because many pages are used in a web site. So it is not natural to work with different variables on each page again and again. To solve this problem we can use php session to easily work on different pages of the website with a specific variable.

The Reason and Solution for PHP session not start or Working

Below are some of the main reasons why php session not start. or php session Code not Working on Live Server and how to solve them.

Error in php code

If the session code is not used properly on the PHP page, then the php session will never work, that is, the session will not start properly. The php session_start () code must always be used first on the php page without any gaps. The following shows the correct way to save php session_start ().

Login page php session start code :-

<?php  
$username = $_POST['username'];  
$password = $_POST['password']; 
 
session_start();
$_SESSION['username'] = $username;
echo"<font color='green'>Login Sucessfully...</font>";	
echo "<script>location='welcome.php'</script>";
?>

This session start login page php code 100% working all PHP version perfectly.

Welcome page php session start code :-

<?php session_start(); ?>

<?php
error_reporting(0);			
	$_SESSION = $_SESSION['username'];
	if($_SESSION['username'])
	{	
	 echo$_SESSION; //-----
        }
?>

its 100% working all php version in live server. If this code does not work on your live hosting server then you can see the following reasons.

Error for web hosting provider

When for some reason the web hosting provider changes their hosting server and changes their IP address. Then the backup that they leave on our website is uploaded properly but it doesn’t work properly. That is why the php version has changed so that the session of our login page cannot be star.

Each web hosting server has different permissions. Permissions may not be allowed properly, even after uploading to all websites. For all of those reasons, PHP cannot be a session star.

Also Read: How to Increase Traffic on Blog Website 2022

If after trying all error fixing this session starting error is not resolved then you can request your web hosting service provider to delete all data and tell him upload backup again then your problem will be 100% fixed.

Friends this problem is very rare for a website. I have experienced this problem once for my website so I discussed this problem with you.

Error for Multiple session start on same page

If different sessions are started on the same page then this session start problem occurs. It is seen that different sessions are started on different pages while logging in. There is no need to start a multiplexer session on the same website. So when coding, you must keep in mind that it is possible to start a session using specific variable keys and work on all pages. This is a very simple method.

Error for Multiple session start on same page

I don’t think there is any need to complicate the work in a way. That work would be very easy and secure with very little coding. It can be seen that there are some programmers who are very experienced programmers. What they do is start multiple sessions while starting the session.

Another reason for the session error is that it is often seen that with the session we send some more beta to the welcome page. As a result, there is a possibility of session error on the welcome page. I don’t think there is any need to send data with error. Because we can customize the welcome page according to our needs using sessions

Example :-

Login page php session start code Multiple session start :-

<?php  
$name = $_POST['name'];
$mobileno = $_POST['mobileno'];
$username = $_POST['username'];  
$password = $_POST['password']; 
 
session_start();
$_SESSION['username'] = $username;
$_SESSION['mobileno'] = $mobileno;
$_SESSION['name'] = $name;
echo"<font color='green'>Login Sucessfully...</font>";	
echo "<script>location='welcome.php'</script>";
?>

Friends I think there is no need to start multiple sessions when he starts the year. I can start a session with a specific data, fully customize it on the welcome page and call and display all the data from there.

<?php  
$username = $_POST['username']; // testuser023 
$password = $_POST['password']; // 123
 
session_start();
$_SESSION['username'] = $username; // testuser023 
echo"<font color='green'>Login Sucessfully...</font>";	
echo "<script>location='welcome.php'</script>";
?>
<?php session_start(); ?>

<?php
eerror_reporting(0);
include('dbdatabase.php');					
	$_SESSION = $_SESSION['username'];
	if($_SESSION['username'])
	{	
	 echo$_SESSION; //-----

$sql = ("SELECT * FROM userdatabase WHERE username='$_SESSION'");
$result = mysqli_query($conn, $sql);
    while($row = mysqli_fetch_assoc($result)) 
    {
     $name = $row['name'];
    $name= $row['mobileno'];
    }

echo $name;
echo"<br>";
echo $name
        }
?>

So friends I can start a session using a specific data and display all the data above that username on the welcome page in this way on our welcome page. No multiple sessions are required for this

The last few words

If you have a similar session start problem then after reading this article I hope your session start problem is solved. Even then, if your session start is a problem, then you will think that there is a problem in your web hosting for which you can not start the session.

So far in my own experience I have discussed with you today all the problems that I have encountered with php session start. I hope that if you follow all these things, your website php session start problem will be solved.


Spread the love

Leave a Comment