Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I am writing a dashboard in PHP which will have multi tenant capabilities the pages designed so far is the login page and then the control panel and the add resource page

The issue is when I login from login page i am able to store session to the second page i.e. the control panel page from control panel there is a button which invokes a page for adding a resource I need variables which are on page 2 to be available on page3 which i am unable to retrieve,

here is my code
Page 1 - Login Page

<form name="adminfrm" action="test.php" method="post" >
</form>

LOGIN TO THE
NETWORK

Network Admin<input type="text" name="netadmin" >
Admin Password<input type="text" name="netpasswd" >
Network Name<input type="text" name="netname" >
<input type="Submit" value="Login">   <input type="reset" value="Clear">

</body>

page 2 Control Panel [test.php]

XML
<?php

session_start();

$_SESSION['network_name'] = $_POST['netname'];
$_SESSION['network_admin'] = $_POST['netadmin'];
$_SESSION['network_password'] = $_POST['netpasswd'];


$network_name = $_POST['netname'];
$network_admin = $_POST['netadmin'];
$network_password = $_POST['netpasswd'];

//echo $network_name;
//echo $network_admin;
//echo $network_password;



$con = mysql_connect("localhost",$netname,$netadmin,$netpasswd);
    if (!$con)
        {
        die('Could not connect: ' . mysql_error());
        }
    else
        {
        echo "Connected to database";
        }


echo "<html>";
echo "<head><title>Wireless Network Overview of : $network_name </title></head>";

$table1="group";
$table2="network";
$table3="node";
$table4="users";

//$result = mysql_list_tables($netnaam);
echo "<table width=\"75%\" border=\"0\" align=\"center\">";
echo "<tr >";
echo    "<td colspan=\"2\" align=\"right\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\"><a href=\"start.php\">Logout</a>";
echo    "</td>";
echo "</tr>";
echo  "<tr bgcolor=\"#993333\"> ";
echo    "<td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" color=\"#FFFFFF\"><B>Network Name :&nbsp;&nbsp;</B>$network_name</font></td>";
echo    "<td align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" color=\"#FFFFFF\" >Action</font></td>";
echo  "</tr>";
echo "<tr bgcolor=\"#CCCCCC\">";
echo    "<td >";
           print "$table1\n";
echo    "</td>";
echo    "<td align=\"center\">";
echo     "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" ><input type=\"button\" value=\"Manage\" ></font>";
echo    "</td>";
echo "</tr>";
echo "<tr bgcolor=\"#CCCCCC\">";
echo    "<td>";
           print "$table2\n";
echo    "</td>";
echo    "<td align=\"center\">";
echo     "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" ><input type=\"Submit\" value=\"Manage\" onClick=window.open('../WebAdmin/addnet/create.php','addnet','height=400,width=600,scrolling=no,noresize') ></font>";
echo    "</td>";
echo "</tr>";
echo "<tr bgcolor=\"#CCCCCC\">";
echo    "<td>";
           print "$table3\n";
echo    "</td>";
echo    "<td align=\"center\">";
echo     "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" ><input type=\"button\" value=\"Manage\"></font>";
echo    "</td>";
echo "</tr>";
      echo "<tr bgcolor=\"#CCCCCC\">";
echo    "<td>";
           print "$table4\n";
echo    "</td>";
echo    "<td align=\"center\">";
echo     "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" ><input type=\"button\" value=\"Manage\"></font>";
echo    "</td>";
echo "</tr>";
echo "</table>";
echo "<br><br>";

echo "<table width=\"75%\" border=\"0\" align=\"center\">";
echo  "<tr bgcolor=\"#993333\"> ";
echo    "<td colspan=\"2\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" color=\"#FFFFFF\"><B>Online User Stats : </font></td>";
echo  "</tr>";
echo "<tr bgcolor=\"#CCCCCC\">";
echo    "<td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" >Online Users </td>";
echo    "<td align=\"center\">";
echo     "<input type=\"button\" value=\"View\">";
echo    "</td>";
echo "</tr>";
echo  "<tr bgcolor=\"#993333\"> ";
echo    "<td colspan=\"2\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" color=\"#FFFFFF\"><B>Traffic Stats : </font></td>";
echo  "</tr>";
echo "<tr bgcolor=\"#CCCCCC\">";
echo    "<td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" >Traffic Stats</td>";
echo    "<td align=\"center\">";
echo     "<input type=\"button\" value=\"View\">";
echo    "</td>";
echo "</tr>";
echo  "<tr bgcolor=\"#993333\"> ";
echo    "<td colspan=\"2\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" color=\"#FFFFFF\"><B>Bandwidth Stats : </font></td>";
echo  "</tr>";
echo "<tr bgcolor=\"#CCCCCC\">";
echo    "<td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" >Bandwidth Stats</td>";
echo    "<td align=\"center\">";
echo     "<input type=\"button\" value=\"View\">";
echo    "</td>";
echo "</tr>";
echo  "<tr bgcolor=\"#993333\"> ";
echo    "<td colspan=\"2\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" color=\"#FFFFFF\"><B>Alarms &amp; Monitors : </B></font></td>";
echo  "</tr>";
echo "<tr bgcolor=\"#CCCCCC\">";
echo    "<td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-1\" >Network Alarms</td>";
echo    "<td align=\"center\">";
echo     "<input type=\"button\" value=\"View\">";
echo    "</td>";
echo "</tr>";
echo "</html>";

?>





from page 2 [test.php]

I am having a button which calls a page which adds resource in my database but i am unable to pass session variables from page2 i.e. test.php to page 3

I want to know how can i achieve this using session variables , do i have to use cookies instead? What I want is once i log in from my login page i will need the user login details one page1 and details on page 2 to be available on all the pages until i logout which destroys my session variables

I am novice in PHP would like to know if any one could provide me with expert insight on the same.

Thanks in Advance

Best Regards
Chetan Jha
Posted

1 solution

Your question is such a mess that I hardly understand your code.

But according to my understanding of your problem, you need to implement a PHP session. A good reference is found here: http://www.w3schools.com/php/php_sessions.asp[^].

Extra tip: Why on earth would you echo all the HTML in the page?

What you're doing right now:
PHP
$_SESSION["foo"] = "bar;
echo "<body style="\font-family: tahoma, verdana\" />";
// some more crap just as the <body> line.
echo "</body>";
?>


What you should do:
PHP
$_SESSION["foo"] = "bar;
?>
<body style="font-family: tahoma, verdana, sans serif">
<!-- rest of the body in HTML -->
// here you want to do a PHP operation again, within the HTML code.
$somevar = 1;
?>
</body>
 
Share this answer
 
v2
Comments
krumia 28-Feb-12 0:58am    
There's a missing < ? php tag in the second code block. CP has a bug preventing me from adding that.
Member 4139457 28-Feb-12 10:22am    
Hi Krumia, the code is just a sample code I am just wanting to pass the session variables to all my pages let that be 1 or 10 pages all the pages should have session information from page 1, yes the echo part in html is a bit messy, thanks for suggesting changes but do let me know if we can have session information on all the pages i checked on w3cschools but no help and i tried googling a bit but to no help.
Thanks in Advance
CJ
krumia 28-Feb-12 21:46pm    
Check out this too: http://php.net/manual/en/function.session-start.php

Once you have started the session in one PHP script, the variables should stay in the server for any subsequent PHP scripts. Session is maintained by a cookie stored in users browser, as you may know. So check if your browser has cookies enabled.

Check your $_POST and $_SESSION variables using isset() function. That should help if something has gone wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900