Jump to content

Recommended Posts

Good day, I am having a weird issue with my sessions first of all I have different pages like so:

 

index.php (login screen)

checklogin.php

login_success.php

 

My login_success.php page works fine it will gather the information from the database and display it.

 

On that page I have 2 links 1 is Update and the other one is Upload Pic.

 

When I go to update.php it is returning me all the right information in my input boxes.

 

but If i select the Upload Pic link i have no more session variable.

 

Upload.php that is loaded when upload Pic is clicked (echo $_SESSION['pusername']; will not even return anything)

<?
session_start();
if(!isset($_SESSION['pusername']) ){
	echo "not set";
}

echo $_SESSION['pusername'];
?>
<html>
<body>

<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

the update.php page when i click the link. this one works perfectly

<?
session_start();
if(!isset($_SESSION['pusername']) ){
	echo "not set";
		
}

ob_start();
$host = "";
$username = "";
$password = "";
$db_name = "";
$tbl_name = "";


mysql_connect("$host","$username","$password") or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select db");

$puser = $_SESSION['pusername'];
$sql = "UPDATE $tbl_name SET Pub_companyName = '$_POST[myusername]',Pub_companyEmail = '$_POST[myemail]', Pub_companyWebsite = '$_POST[mywebsite]' WHERE Pub_User = '$puser'";
$result=mysql_query($sql) or die(mysql_error());

$result = mysql_query($sql);

if(!$result){
	die("Error running $sql:" . mysql_error());
}
header("location:/test/functions/login_success.php");
echo " 1 item added ";
?>



Link to comment
https://forums.phpfreaks.com/topic/281998-weird-session-issues/
Share on other sites

you didn't state if you are getting the echo "not set"; output? depending on that output, the troubleshooting is different -

 

if you are getting the 'not set' message, it means your session id likely didn't match (most likely because the host-name/sub-doman in the url's changed.)

 

if you are not getting the 'not set' message and nothing is displayed from the echo $_SESSION['pusername']; statement, it likely means that your code is accidentally overwriting the session variable.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.