PHP session being destroyed prematurely - php

I am a php newbie and I am using MAC OS. I recently set up a website and test it under localhost. It works fine until one day I tried to rename my home folder, and quit halfway when switching from root back to the one that I have renamed. Then I logged out from the root user and loggin in the one that I have renamed. Then I found that I have to reset everything. The application folder had been moved outside the user home dir to the same level with the user folder.
Here's the problem(I don't know whether it is caused by the above action.)
I let a user log in with username and password, and use a session variable to store the username. I check with:
echo $_SESSION['name'];
echo session_status();
The first one shows the username I have input, and the second one prints 2
So I think that the username was stored in that session variable.
But then whenever the user enter another page, the session variable is destroyed.
What is the problem?
Here's the code that I write for every page as page header. It contains the log in box. It used to work fine.
<?php
echo '<div id="pageheader">
<div class="wrap">
<div class="logo">
<img src="pics/1.gif" height="45px">
</div>
<ul id="nav">
<li>New Arrival&nbsp&nbsp&nbsp/</li>
<li>Hot&nbsp&nbsp&nbsp/</li>
<li>By School&nbsp&nbsp&nbsp/
<ul >
<li>ADM</li>
<li>CEE</li>
<li>EEE</li>
<li>HSS</li>
<li>MAE</li>
<li>MSE</li>
<li>NBS</li>
<li>SBS</li>
<li>SCBE</li>
<li>SCI</li>
<li>SPMS</li>
<li>SCE</li>
</ul>
</li>
<li>By Course&nbsp&nbsp&nbsp/
<ul>
<li>Mathematics</li>
<li>Computing</li>
<li>Accounting</li>
<li>Business Law</li>
<li>Physics</li>
<li>Chemistry</li>
<li>Biology</li>
</ul>
</li>
<li>By Kind&nbsp&nbsp&nbsp/</li>
</ul>
<ul id="log">';
function generateLogin(){
echo ' <li id="login">
<a id="login-trigger" href="#">login&nbsp<span>&#x25BC</span></a>
<div id="login-content">
<form action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">
<fieldset class="inputs">
<input name="user" type="text" placeholder="Username" class="reqd" />
<input name="loginpw" type="password" placeholder="Password" class="reqd" />
</fieldset>
<fieldset class="actions">
<input type="submit" class="button1" value="Log in" />
<label><input name="keep" type="checkbox" value="yes" />Keep me signed in</label>
</fieldset>
</form>
</div>
</li>
<li id="signup">
<a id="signup-trigger" href="#">signup&nbsp<span>&#x25BC</span></a>
<div id="signup-content">
<form action="signup.php" method="post" enctype="multipart/form-data">
<fieldset class="inputs">
<input name="username" id="username" type="text" placeholder="Username (at least 6 characters)" class="reqd user" />
<input name="email" id="email" type="email" placeholder="john#example.com" class="reqd email" />
<input id="passwd1" type="password" placeholder="Password (at least 6 characters)" class="reqd pd" />
<input name="pswd" id="passwd2" type="password" placeholder="Confirm your password" class="reqd passwd1" />
</fieldset>
<fieldset class="actions">
<input type="submit" class="button1" value="Sign up" /> <input type="reset" class="button1" />
</fieldset>
</form>
</div>
</li>
';
}
session_start();
if(!isset($_SESSION['name']) or $_GET['logout'] == 1){
if($_GET['logout'] == 1){unset($_SESSION['name']);}
if(isset($_POST['user'])){
$link = mysqli_connect('localhost','root','root','bookstore');
if (!$link){
die('Could not connect: ' . mysqli_error());
}
try {
$sql = "SELECT username FROM user
WHERE username='$_POST[user]' AND
pswd=MD5('$_POST[loginpw]')";
$sqlUser = "SELECT username FROM user
WHERE username='$_POST[user]'";
$result1 = mysqli_query($link, $sql);
$result2 = mysqli_query($link, $sqlUser);
if (!mysqli_fetch_row($result1)){
if(!mysqli_fetch_row($result2)){
throw new Exception("User ".$_POST['user']." does not exist!");
}
else{
throw new Exception("Incorrect password!");
}
}
else{
$_SESSION['name'] = $_POST['user'];
echo '
<ul id="log">
<li>Logout</li>
<li>Hi, '.$_POST['user'].'</li>
</ul>';
}
}catch(Exception $e){
echo "<script type='text/javascript'>alert('".$e->getMessage()."');</script>";
generateLogin();
}
mysqli_close($link);
}
else{
generateLogin();
}
}
else{
$name = $_SESSION['name'];
echo '
<ul id="log">
<li>Logout</li>
<li>Hi, '.$_SESSION['name'].'</li>
</ul>';
}
echo ' </ul>
<div id="search">
<form action="book.php" name="search" method="get" enctype="multipart/form-data">
<input name="q" id="q" autocomplete="off" onkeyup="showHint(this.value)" type="text" size="100" placeholder="Search..." />
<input type="submit" class="button1" value="Search" />
</form>
</div>
<div id="suggestBox">
<ul>
<div id="txtHint">
</div>
</ul>
</div>
</div>
</div>';
?>

You have to start the session on every page you use sessions
<?php
session_start();
// now I can use my sessions in this page and
// I should start the session on each page I use them
?>
You should use session_start() before any html output so in your case move session_start() before the first echo!
<?php
// move session_start here
session_start();
echo '<div id="pageheader">
<div class="wrap">';
?>

You need to run session_start() on every page where you're expecting to use $_SESSION data...seems like you should add session_start to the top of this page, has to be included before anything is output.

Related

Search function with php PDO and mysql

I'm Working on a Webshop for a School Project. The website is done and works as intended. Except for the Search function, which works but does something weird.
This is the Code from my Search Page
<?php
$stmt = $auth_user->runQuery("SELECT * FROM customer WHERE id=:id");
$stmt->execute(array(":id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if(isset($_POST['btn-offer']))
{
try
{
$auth_user->redirect('offer.php');
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
<form method="post" class="form-signin">
<div class="form-group">
<input type="text" class="form-control" name="search" placeholder="Enter an Item"/> <br />
<button type="Search" name="btn-search">
<i class="glyphicon glyphicon-open-file"></i> Search
</button>
<hr />
</div>
<?php
if(isset($error)){
foreach($error as $error){
?>
<div class="alert alert-danger">
<i class="glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?>
</div>
<?php
}
}
else if(isset($_GET['search'])){
//$search_term = $_SESSION['search_term'];
$stmt = $user_req->runQuery("SELECT * FROM requests WHERE item LIKE :search");
$stmt->bindValue(":search","%".$_SESSION['search_term']."%");
$stmt->execute();
while($userReq=$stmt->fetch(PDO::FETCH_ASSOC)){
?><h6> Request ID </h6><?php echo($userReq['id']); ?> <br /><br /> <?php
?><h6> Requested Item </h6><?php echo($userReq['Item']); ?> <br /><br /> <?php
?><h6> Requested Price </h6><?php echo($userReq['price']); ?> <br /><br /> <?php
?><h6> Requested Quantity </h6><?php echo($userReq['quantity']); ?> <br /><br /> <?php
?><h6> Subject </h6><?php echo($userReq['subject']); ?> <br /><br /> <?php
?><h6> Description </h6><?php echo($userReq['descr']);
?>
<br />
<form action="offer.php" method="post" class="form-signin">
<input type="hidden" class="form-control" name="offer_id" value="<?php echo htmlspecialchars($userReq['id']); ?>"/> <br />
<input type="hidden" class="form-control" name="offer_item" value="<?php echo htmlspecialchars($userReq['Item']); ?>"/> <br />
<button type="Search" name="btn-offer">
<i class="glyphicon glyphicon-open-file"></i> Create Offer
</button>
</form>
<form action="all_offers.php" method="post" class="form-signin">
<input type="hidden" class="form-control" name="offer_id" value="<?php echo htmlspecialchars($userReq['id']); ?>"/> <br />
<button type="Search" name="btn-show">
<i class="glyphicon glyphicon-open-file"></i> Show Offers
</button>
</form>
<hr />
<?php
}
?>
<?php
}
?>
<br />
</form>
It displays everything as desired (all entries containing the search input).
But if i click on Create Offer, the hidden Input Types gets passed to my Search function just once. It wont update it with the new hidden variables if i click on another create offer button.
Offer.php file
<?php
if(isset($_POST['offer_id']))
{
$_SESSION['off_rid'] = $_POST['offer_id'];
$_SESSION['offer_item'] = $_POST['offer_item'];
}
?>
<h2 class="form-signin-heading">Create Offer for Request ID <?php echo htmlspecialchars($_SESSION['off_rid']); ?></h2><hr />
<form method="post" class="form-signin">
<input type="hidden" class="form-control" name="off_rid" value="<?php echo htmlspecialchars($_SESSION['off_rid']); ?>"/> <br />
<div class="form-group">
<label>Requested Item</label>
<input type="text" class="form-control" name="off_item" placeholder="<?php echo htmlspecialchars($_SESSION['offer_item']); ?>" value="<?php if(isset($error)){echo htmlspecialchars($_SESSION['offer_item']);}?>" readonly/>
</div>
<div class="form-group">
<input type="number" class="form-control" name="off_price" placeholder="Enter a Price" value="<?php if(isset($error)){echo $off_price;}?>" />
</div>
<div class="form-group">
<input type="number" class="form-control" name="off_quant" placeholder="Enter the Quantity" value="<?php if(isset($error)){echo $off_quant;}?>" />
</div>
<hr />
<div class="form-group">
<button type="submit" name="btn-createoffer">
<i class="glyphicon glyphicon-open-file"></i> Post Offer
</button>
</div>
<?php
if(isset($error)){
foreach($error as $error){
?>
<div class="alert alert-danger">
<i class="glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?>
</div>
<?php
}
}
else if(isset($_GET['posted'])){
?>
<div class="alert alert-info">
<i class="glyphicon glyphicon-log-in"></i> Successfully submitted the Offer!
</div>
<?php
}
?>
<br />
</form>
If i search for every entry containing "ni" i get all the entries, the hidden Inputtypes are also correct.
If i click on create offer it should write the id and the item on the redirected Page but it only works once. if i go back and search another item it still displays the info from the first item i created an offer.
Can anybody point out what i'm doing wrong. I'm stuck on this Problem since a few days and just cant figure it out.
Thanks in advance

Button implements the wrong code when press 'enter' button

I am writing code that is meant to log in users.
The login and search worked before but, ever since I combined the two the login form doesn't implement it's own code and instead, it runs the search code
EDIT: I found out why this happens, it's because I have been pressing enter instead of selecting login. So now I want to know, how do I press enter and implement the login code.
Below is the headerPublic.php which contains the search code
<?php
//---------------------BEGIN SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
if(isset($_POST["search_button"]))
{
//PHP SEARCH CODE
}
//---------------------END SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
?>
<html>
<head>
<title>VCR Exchange</title>
</head>
<body>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>Register</li>
<li>Log In</li>
</ul>
</nav>
And this is the login.php.
<?php require('connect.php'); ?>
<?php require('headerPublic.php'); ?>
<?php require('session.php'); ?>
<form class="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="inputEmail" >Email address</label>
<input type="email" name="email" placeholder="Email address">
<label for="inputPassword" >Password</label>
<input type="password" name="password" placeholder="Password">
<button name="login" type="submit">Login</button>
</form>
</body>
</html>
<?php
// IF LOGIN BUTTON IS CLICKED:
if (isset($_POST['login']))
{
//LOG IN CODE
}
?>
The search form was missing a closing form tag
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</form>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->

store username to use in a later form

I have a form where I enter a username and it gets the users information. after calling for the users information I have another form wtih a checkbox for "banned" where I can ban or unban the user. But how can I store the entered username from the first form, to later use it in the second form where I check the banned checkbox?
code:
<form action="" method="post" id="msform">
<input type="text" name="datausername" placeholder="Username" maxlength="64" readonly onfocus="this.removeAttribute('readonly');"/>
<input type="submit" name="userdata" value="Get Data" class="databutton">
</form>
<?php
if(isset($_POST['userdata'])){
$datausername = $_POST['datausername'];
$sql = "SELECT * FROM users WHERE username = '$datausername'";
$result = $db->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '
<div class="container" style="width:100%;">
<div class="flag note note--secondary">
<div class="flag__body note__text" style="width:100%;">
<h1>Personal Information</h1>
ID : <div class="fr">'.$row['id'].'</div><br />
E-mail: <div class="fr">'.$row['email'].'</div><br />
Username: <div class="fr">'.$row['username'].'</div><br />
Firstname: <div class="fr">'.$row['firstname'].'</div><br />
Lastname: <div class="fr">'.$row['lastname'].'</div><br />
<br />
Activated: <div class="fr">'.$row['active'].'</div><br />
Banned: <div class="fr">'.$row['banned'].'</div><br />
<br />
<h1>Data Information</h1>
Title: <div class="fr">'.$row['title'].'</div><br />
Rank: <div class="fr">'.$row['rank'].'</div><br />
Level: <div class="fr">'.$row['level'].'</div><br />
Exp: <div class="fr">'.$row['exp'].'</div><br />
<br />
<h1>Forum / Profile stats</h1>
Forum Posts: <div class="fr">0</div><br />
Forum Threaths: <div class="fr">0</div><br />
Comments: <div class="fr">0</div><br />
Awards: <div class="fr">0</div><br />
Friends: <div class="fr">0</div><br />
Followers: <div class="fr">0</div><br />
<br />
<h1>Security Information</h1>
IP: <div class="fr">'.$row['ip'].'</div><br />
Last IP: <div class="fr">'.$row['active_ip'].'</div><br />
Secret Question: <div class="fr">'.$row['question'].'</div><br />
Timestamp: <div class="fr">'.$row['timestamp'].'</div><br />
Activate Link: <div class="fr">link</div><br />
<br />
</div>
<a href="#" class="note__close">
<i class="fa fa-times"></i>
</a>
</div>
</div>';
if($title == 'Head Admin' || $title == 'Admin'){
if($row['banned'] == '1'){
$checkbox = '<label><input type="checkbox" name="confirm" checked/></label>';
} else {
$checkbox = '<label><input type="checkbox" name="confirm" /></label>';
}
echo '
<div class="container" style="margin-top:20px; width:100%;">
<div class="flag note note--secondary">
<div class="flag__body note__text" style="width:100%;">
<h1>Settings</h1>
<form method="post" action="" id="msform" style="text-align:left;">
Ban: <div class="fr">'.$checkbox.'</div>
<div style="padding:10px;"></div>
<input type="submit" name="dataset" value="Update" class="databutton">
</form>
</div>
<a href="#" class="note__close">
<i class="fa fa-times"></i>
</a>
</div>
</div>
';
}
}
} else {
echo '
<div class="container" style="margin:0 auto; width:100%;">
<div class="flag note note--secondary">
<div class="flag__image note__icon">
<i class="fa fa-user"></i>
</div>
<div class="flag__body note__text">
User not found!
</div>
<a href="#" class="note__close">
<i class="fa fa-times"></i>
</a>
</div>
</div>';
}
}
$db->close();
?>
This is the second form where I want to have the username stored to re use i to update the "banned" checkmark:
if($title == 'Head Admin' || $title == 'Admin'){
if($row['banned'] == '1'){
$checkbox = '<label><input type="checkbox" name="confirm" checked/></label>';
} else {
$checkbox = '<label><input type="checkbox" name="confirm" /></label>';
}
echo '
<div class="container" style="margin-top:20px; width:100%;">
<div class="flag note note--secondary">
<div class="flag__body note__text" style="width:100%;">
<h1>Settings</h1>
<form method="post" action="" id="msform" style="text-align:left;">
Ban: <div class="fr">'.$checkbox.'</div>
<div style="padding:10px;"></div>
<input type="submit" name="dataset" value="Update" class="databutton">
</form>
</div>
<a href="#" class="note__close">
<i class="fa fa-times"></i>
</a>
</div>
</div>
PS: title in
if($title == 'Head Admin' || $title == 'Admin'){
Is your logged in title, so this will only be an option if you are either Head Admin or Admin
You can create a hidden text field to store it, then pass it via the POST data to the next stage:
(instead of using datausername here, you should be using the row ID returned from your SQL query)
<form method="post" action="" id="msform" style="text-align:left;">
Ban: <div class="fr">'.$checkbox.'</div>
<div style="padding:10px;"></div>
<input type="submit" name="dataset" value="Update" class="databutton">
<input type="hidden" name="username" value="<?=$datausername?>">
</form>
Then in the next stage $_POST['datausername'] will exist.
OR
Use sessions (the better solution to be honest, less prone to hacking)
For example, you can start a new session, shove some data into it and unset the session after your finished with it.
In your index.php / config.php / whatever
session_start();
In your php file:
$datausername = $_POST['datausername'];
$_SESSION['customdata']['username'] = $datausername;
if($title == 'Head Admin' || $title == 'Admin') {
if ( isset($_SESSION['customdata']) ) {
$username = $_SESSION['customdata']['userid'];
//ban the user here, update SQL etc.
//Unset the session variable
unset($_SESSION['customdata'];
}
}
In your form add a hidden field to contain the id of the user. You can then use that as a key for the update query in the second form
<form method="post" action="" id="msform" style="text-align:left;">
<input type="hidden" name="key" value="<?php echo $row['id']; ?>">
Ban: <div class="fr">'.$checkbox.'</div>
<div style="padding:10px;"></div>
<input type="submit" name="dataset" value="Update" class="databutton">
</form>
Alternativley use the session
In form one add thsi at the top of the script
<?php
session_start();
then load a value ito the session
$_SESSION['Users_id'] = $row['id'];
Now in the second form you will use that value in the UPDATE
<?php
session_start();
if ( isset($_SESSION['users_id']) ) {
$key = $_SESSION['users_id'];
} else {
// we really should not be in this form
header('Location: somewhere_else.php');
}

PHP : Login in to the admin page

I am trying to login into the admin and lecturer page in the following code.But it is not working properly.When i login after entering loginid and password, click on submit , no error occured.
admin.php
<?php
session_start();
if(isset($_SESSION["userid"]))
{
if($_SESSION["type"]=="admin")
{
header("Location: dashboard.php");
}
else
{
header("Location: lectureaccount.php");
}
}
include("header.php");
include("conection.php");
if(isset($_POST["uid"]) && isset($_POST["pwd"]) )
{
// echo "sdfsd". $_POST[uid];
$result = mysql_query("SELECT * FROM administrator WHERE adminid='$_POST[uid]'");
while($row = mysql_fetch_array($result))
{
$pwdmd5 = $row["password"];
}
if(md5($_POST["pwd"])=='$pwdmd5')
{
$_SESSION["userid"] = $_POST["uid"];
$_SESSION["type"]="admin";
header("Location: dashboard.php");
}
else
{
$log = "Login failed.. Please try again..";
}
}
if(isset($_POST["luid"]) && isset($_POST["lpwd"]))
{
$result = mysql_query("SELECT * FROM lectures WHERE lecid='$_POST[luid]'");
while($row = mysql_fetch_array($result))
{
$pwdm= $row["password"];
$_SESSION["lecname"] = $row["lecname"];
$_SESSION["coid"] = $row["courseid"];
}
//echo"pwd". md5($_POST["lpwd"]);
if(md5($_POST["lpwd"])==$pwdm)
{
//echo $_POST["lpwd"];
$_SESSION["userid"] = $_POST["luid"];
$_SESSION["type"]=="lecturer";
header("Location: lectureaccount.php");
}
else
{
$log12 = "Login failed.. Please try again..";
}
}
?>
<section id="page">
<header id="pageheader" class="normalheader">
<h2 class="sitedescription">
</h2>
</header>
<section id="contents">
<article class="post">
<header class="postheader">
<h2><u>Admin Login</u></h2>
<?php $log = isset($_POST['log']) ?>
<h2><?php echo $log;?></h2>
</header>
<section class="entry">
<form action="admin.php" method="post" class="form">
<p class="textfield">
<label for="author">
<small>Admin Login ID (required)</small>
</label>
<input name="uid" id="uid" value="" size="22" tabindex="1" type="text">
</p>
<p class="textfield">
<label for="email">
<small>Password (required)</small>
</label>
<input name="pwd" id="pwd" value="" size="22" tabindex="2" type="password">
</p>
<p>
<input name="submit" id="submit" tabindex="5" type="image" src="images/submit.png">
<input name="comment_post_ID" value="1" type="hidden">
</p>
<div class="clear"></div>
</form>
<form action="admin.php" method="post" class="form">
<div class="clear">
<hr />
<header class="postheader">
<h2><u>Lectures Login</u></h2>
<?php $log12 = isset($_POST['log12']) ?>
<h2><?php echo $log12;?></h2>
</header>
<section class="entry">
<p class="textfield">
<label for="author2"> <small><br />
Lecture Login ID (required)</small> </label>
<input name="luid" id="luid" value="" size="22" tabindex="3" type="text" />
</p>
<p class="textfield">
<label for="email2"> <small>Password (required)</small> </label>
<input name="lpwd" id="lpwd" size="22" tabindex="4" type="password" />
</p>
<p>
<input name="submit2" id="submit2" tabindex="5" type="image" src="images/submit.png" />
<input name="comment_post_ID2" value="1" type="hidden" />
</p>
<div class="clear"></div>
</form>
<div class="clear"></div>
</section>
</div>
</section>
</article>
</section>
<?php
include("adminmenu.php");
include("footer.php"); ?>
Database:
table fields in administrator are: adminid,password,adminname,address,contactno
table fields in lectures are:
lecid,password,courseid,lecname,gender,address,contactno.
Please provide solution for this issue.
instead of using this code
if(md5($_POST["pwd"])=='$pwdmd5')
use this
if(md5($_POST["pwd"])==$pwdmd5)
In the first case, the hashed pasword is compared to the string $pwdmd5, in the second to the content of $pwdmd5

Informations are not sent by form

I wrote a code and i used Boostrap to make 2 dropdown : Sign In and Sign Up. After i complete input fields , informations aren't send ... and submit button redirect me to index.php?username="What is in username field"&password="Password typed" .
I wanna send data to informations index.php?tab=SignIn... What could be wrong ?
<ul class="nav navbar-nav nav pull-right">
<li class="animated dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-lock fa-2x"></i><br /> Register <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<?php
#$_SESSION['username2'] = $_POST['username'];
#$_SESSION['email'] = $_POST['email'];
#$_SESSION['password'] = $_POST['password'];
?>
<form class="form" id="formLogin" action="index.php?tab=SignUp">
<li><div class="form-group">
<input type="text" name="username" id="username" class="form-control" placeholder="Username" value="<?= $_SESSION['username2'] ?>" required/>
</div></li>
<li><div class="form-group">
<input type="email" name="email" id="email" class="form-control" placeholder="E-Mail Address" value="<?= $_SESSION['email'] ?>" required/>
</div></li>
<li><div class="form-group">
<input type="password" name="password" id="password" class="form-control" placeholder="Password" value="<?= $_SESSION['password'] ?>" required/>
</div></li>
<li class="divider"></li>
<input type="submit" name="register" class="btn btn-success" value="Register" tabindex="7">
</form>
</ul>
</li>
</ul>
replace this
<form class="form" id="formLogin" action="index.php?tab=SignUp">
with this
<form class="form" id="formLogin" action="index.php" method="post">
<input type="hidden" name="tab" value="SingUp" />
and in your index.php get tab parameter by $_POST['tab']
change
<form class="form" id="formLogin" action="index.php?tab=SignUp">
to
<form class="form" id="formLogin" action="index.php?tab=SignUp" method="post">
Nope. Just call index.php each time. No suffixes to the url ever. If you want a special value, then create a hidden element in the form, with the value set so the second time the user hits index.html, the value will populate...
<?php
#$_SESSION['username2'] = $_POST['username'];
#$_SESSION['tab'] = $_POST['tab']; // set in the original form in a hidden field.
#$_SESSION['email'] = $_POST['email'];
#$_SESSION['password'] = $_POST['password'];
?>
Somewhere along the line do a test if ($_POST['tab'] == "SignUp") then do whatever. If $_POST['tab'] isnt = SignUp, then you know its the first time to that page....
Keep it very simple. Less is more! (oops.. I'm a duplicate of the posting by Gabriele Pieretti) I'm upvoting GP! thx.

Categories