The session is not working properly in PHP - javascript

The session is not working properly in PHP. The login page is working fine. But after redirecting to my home page I couldn't able to see my login details it throws this errorNotice : Undefined index: username in C:\xampp\htdocs\final\header.php on line
and if I use the if-else state to hide my login/signup button it's not working. So please someone help me with this issue
My Login page
<link rel="stylesheet" href="css/auth.css">
<body>
<div class="login-box"> <h2>Login</h2> <form action="handleLogin.php" method="post">
<div class="user-box">
<input type="text" name="loginEmail" required="">
<label>Email</label>
</div>
<div class="user-box">
<input type="password" name="loginPass" required="">
<label>Password</label>
</div>
<a href="#">
<span></span>
<span></span>
<span></span>
<span></span>
<input type="submit" value="LogIn" name="submit">
</a><br>
<a class="nav_btn" href="signup.php"><i class="icon_profile"></i>Create New Account</a> </form> </div>
</body> </html>
LoginHandle page
<div class="login-box"> <h2>Login</h2> <form action="handleLogin.php" method="post">
<div class="user-box">
<input type="text" name="loginEmail" required="">
<label>Email</label>
</div>
<div class="user-box">
<input type="password" name="loginPass" required="">
<label>Password</label>
</div>
<a href="#">
<span></span>
<span></span>
<span></span>
<span></span>
<input type="submit" value="LogIn" name="submit">
</a><br>
<a class="nav_btn" href="signup.php"><i class="icon_profile"></i>Create New Account</a> </form> </div>
</body> </html>
My header session
echo ' <form class="form-inline my-2 my-lg-0" >
<p class="text-light my-0 mx-2">Welcome'.$_SESSION["username"].' </p>
</form>';

I think you should use the post method for the form and then store the values in the sessions but remember to start session first
Here you logged in
<php?
// Check to see if we have some POST data, if we do process it
if ( isset($_POST['name']) && isset($_POST['pass']) ) {
$_SESSION["name"] = htmlentities($_POST["email"]);
header( 'Location: view.php' ) ;
return;
}
?>
<form action="handleLogin.php" method="post">
<div class="user-box">
<input type="text" name="loginEmail" required="">
<label>Email</label>
</div>
<div class="user-box">
<input type="password" pass="loginPass" required="">
<label>Password</label>
</div>
<input type="submit" value="LogIn" name="submit">
</form>

Related

i have problem with my javascript on codeigniter, parse to javascript

i have some problem, i want to push my data to form html with javascript obj but it can't push with id
this is my javascript
{if {form_case} == ubah}
<script type="text/javascript">
var data={data_by_id};
for (var obj in data)
{
alert(data[obj]);
$("#" + obj).val(data[obj]);
}
</script> {/if}
this my form html
<form class="form" form-case="{form_case}">
<div class="form-group">
<label for="Nama">Nama</label>
<input type="text" class=" riset form-control" id="nama_user" name="nama_user" placeholder="">
<div>
<?php print form_error('nama_user', '<small class="text-danger">', '</small>') ?>
</div>
</div>
<div class="form-group">
<label for="Username">Username</label>
<input type="text" class="form-control" id="username" name="username">
<div>
<?php print form_error('username', '<small class="text-danger">', '</small>') ?>
</div>
</div>
<div class="form-group">
<label for="Password">Password</label>
<input type="password" class="form-control" id="password" name="password">
<div>
<?php print form_error('password', '<small class="text-danger">', '</small>') ?>
</div>
</div>
<div class="form-group">
<div class="float-right">
<button class="btn btn-sm btn-primary" name="simpan" data-link="{base_url}/{lvl_auth}/{base_class}/store">Simpan</button>
<button type="reset" class="btn btn-sm btn-success" name="reset">Reset</button>
</div>
</div>
</form>
this my result in inspect element
enter image description here
then this ini my result on html it can't show the value in field
enter image description here

how to setup auto-close for popup in framework7 version1

i am using a framwork7 js version 1 for my android mobile app.but there is a problem in login popup, after the successful login the router is working, but the popup is still on the screen, it is not close.
index file popup code
<div class="popup popup-login">
<div class="content-block">
<h4>LOGIN</h4>
<div class="loginform">
<form id="LoginForm" method="post" class="close-panel">
<div id="msgprint" style="display: block;"></div>
<input type="text" name="Username" id="username" value="" class="form_input required" placeholder="Username" />
<input type="password" name="Password" id="password" value="" class="form_input required" placeholder="Password" />
<input type="button" name="submit" class="form_submit" id="submitlogin" onclick="loginHost()" value="SIGN IN" />
</form>
<div class="signup_bottom">
<p>Don't have an account?</p>
SIGN UP
</div>
</div>
<div class="close_popup_button">
<img src="images/icons/black/menu_close.png" alt="" title="" />
</div>
</div>
</div>
javascript for the router page
if(response.data.is_success){
mainView.router.loadPage({url:'user-product.html', ignoreCache:true,
reload:true });
}
if anyone knows the solutions. please answer.

onClick Function can work only in loading Web Browser, and can't work totally after loading Web Browser

When I Click the Submit button with id 'submitPasscode', I want to hide the div tag (with id 'passcodeCard') and want to display the div tag (with id 'loginCard').
After Clicking it, onClick function 'checkPasscode()' is worked, but this function works only when loading web browser. It means that div tag (with id 'passcodeCard') didn't hide, and div tag (with id 'loginCard') didn't display after loading web browser.
I would like to know what is wrong with this code to work onClick Function works well.
Here is the code:
<div id="passcodeCard" class="loginDiv" style="margin-top: 10%;" style="display: inline;">
<form id="form" class="form-horizontal" style="padding-top: 5%;">
<div class="group">
<input type="text" id="passcode" name="passcode" placeholder="Enter Passcode"/>
<span class="bar"></span>
<label>Enter Passcode</label>
<button type="submit" class="button buttonBlue" style="margin-top: 5%;" id="submitPasscode" onclick="checkPasscode()">Submit</button>
</div>
</form>
</div>
<div id="loginCard" class="loginDiv widgetHeight" style="display: none;">
<img class="img-responsive user-logo" src="layouts/v7/resources/Images/hims5.png">
<div>
<span class="{if !$ERROR}hide{/if} failureMessage" id="validationMessage">{$MESSAGE}</span>
<span class="{if !$MAIL_STATUS}hide{/if} successMessage">{$MESSAGE}</span>
</div>
<div id="loginFormDiv">
<form class="form-horizontal" method="POST" action="index.php">
<input type="hidden" name="module" value="Users"/>
<input type="hidden" name="action" value="Login"/>
<div class="group">
<input id="username" type="text" name="username" placeholder="Username" value="admin">
<span class="bar"></span>
<label>Username</label>
</div>
<div class="group">
<input id="password" type="password" name="password" placeholder="Password" value="password">
<span class="bar"></span>
<label>Password</label>
</div>
<div class="group">
<button type="submit" class="button buttonBlue">Sign in</button><br>
<a class="forgotPasswordLink" style="color: #15c;">forgot password?</a>
</div>
</form>
</div>
</div>
<script>
function checkPasscode(){
if(document.getElementById("passcode").value == "passcode")
{
document.getElementById("form").style.display = "none";
document.getElementById("loginCard").style.display = "";
}
}
</script>
I don't completely understand your question, but is this what you wanted. I added some extra features such as making the fields required. Please let me know if this helped:
Here is the code:
<div id="passcodeCard" class="loginDiv" style="margin-top: 10%;" style="display: inline;">
<form id="form" class="form-horizontal" style="padding-top: 5%;">
<div class="group">
<input type="password" id="passcode" name="passcode" placeholder="Enter Passcode" required/>
<span class="bar"></span>
<label>Enter Passcode</label>
<button type="submit" class="button buttonBlue" style="margin-top: 5%;" id="submitPasscode" onclick="checkPasscode()">Submit</button>
</div>
</form>
</div>
<div id="loginCard" class="loginDiv widgetHeight" style="display: none;">
<img class="img-responsive user-logo" src="layouts/v7/resources/Images/hims5.png">
<div>
<span class="{if !$ERROR}hide{/if} failureMessage" id="validationMessage">{$MESSAGE}</span>
<span class="{if !$MAIL_STATUS}hide{/if} successMessage">{$MESSAGE}</span>
</div>
<div id="loginFormDiv">
<form class="form-horizontal" method="POST" action="index.php">
<input type="hidden" name="module" value="Users"/>
<input type="hidden" name="action" value="Login"/>
<div class="group">
<input id="username" type="text" name="username" placeholder="Username" value="admin" required>
<span class="bar"></span>
<label>Username</label>
</div>
<div class="group">
<input id="password" type="password" name="password" placeholder="Password" value="password" required>
<span class="bar"></span>
<label>Password</label>
</div>
<div class="group">
<button type="submit" class="button buttonBlue">Sign in</button><br>
<a class="forgotPasswordLink" style="color: #15c;">forgot password?</a>
</div>
</form>
</div>
</div>
<script>
function checkPasscode(){
if(document.getElementById("passcode").value == "passcode")
{
document.getElementById("form").innerHTML = "";
document.getElementById("loginCard").style.display = "block";
}
}
</script>

how to remove onclick from <form> and <button>

Hello I have a problem with this following code :
<form id="signon_form" method="post" action="r1.php" class="form-signin" name="">
<div id="error" class="error">
<img src="images/error_button.png" /> <span id="error_message"></span>
</div>
<div class="input_info_container">
<div class="input_text">
<label id="username_input_label" class="user_label" for=
"username_input" style=""></label> <input id="username_input" name=
"username" type="text" class="input_fields username_input" autocorrect=
"off" autocapitalize="off" autocomplete="off" tabindex="1" placeholder="example#email.ca"/>
</div>
<div class="input_info help_icon">
<a id="help_icon" class="help_link" href="javascript:;" data-toggle="modal" data-target="#myModal" tabindex="3">
<img src="images/icons/helpIcon.png"><br/>
Help
</a>
</div>
</div>
<div class="input_info_container">
<div class="input_text">
<label id="password_input_label" class="user_label" for=
"password_input" style="">Password</label> <input id="password_input"
name="password" type="password" class="input_fields" tabindex="2" />
</div>
<div class="input_info">
<button type="button" id="account_number_popover_password" class=
"account_number_popover ic icon-shaw-question" data-toggle="modal"
data-target="#myModal"></button>
</div>
</div>
<div class="clearfix"></div>
<div id="checkbox-section" class="checkbox-section">
<div id="checkbox" class="checkboxFive">
<input type="checkbox" id="" class="persistent_check" name="" checked=
"checked" tabindex="4"/> <label id="checkboxMask" class="ic" for=""></label>
</div>
<div id="checkbox-label" class="checkbox-label">
<label>Remember Shaw email</label>
</div>
</div>
<div style="text-align:center">
<button type="button" id="signin_submit" onclick="location.href='r1.php'" class=
"button button_disabled" tabindex="5">Sign in</button>
</div>
<div id="description-section" class="description-section">
<center>
<div id="forgot" class="description_one">
To recover your email address or to reset your password visit the Internet section in My Account.
</div>
<div id="create_new_account" class="description_two hidden-xs hidden-sm hidden-md">
<span class="dont-have-account-phone">Don't have an account?</span>
<a target="_self" data-event="navigation-element" data-value=
"signon|body|create-one-now-link" id="create_one_now" href=
"#"><span class=
"dont-have-account-desktop">Don't have an account?</span>
<span class="create-one-now-url">Create one now.</span></a>
</div>
</center>
</div><input type="hidden" id="anchor" name="anchor" value="" />
</form>
you see that I have an action in the form which is r1.php and the button has a onclick="location.href='r1.php'" if I delete it the Sign In button doesn't work I want to get rid of it can you help me guys I'm a begginer and experimenting with website's source code to learn a little please if you could help me I'll be so greatfull
What you are looking for is an actual form submission, rather than a simple redirection.
Instead of:
<button type="button" id="signin_submit" onclick="location.href='r1.php'" class="button button_disabled" tabindex="5">Sign in</button>
You need an input type of submit:
<input type="submit" value="Submit" id="signin_submit">
This tells the button to actual POST the data. Note that you may need to slightly tweak your CSS to give the desired display.
Hope this helps!

Make a form to pass parameters

I've a form but it doesn't pass the parameters 'url' and 'USERNAME' to the next page. Is there something wrong?
I must use <button> instead of <input> for styling issues.
Here is the form:
<form action="/confirmation/index.php" method="post" class="form-wrap">
<div class="loader-wrap">
<div class="loader-txt">
</div>
</div>
<div class="field-set url-field">
<input type="text" name="url" data-placeholder="Your Website URL" maxlength="50" class="validate">.
<button name="url_btn" type="button" class="btn url-btn">Scan My Site!</button>
</div>
<div class="field-set email-field">
<input type="text" name="USERNAME" data-placeholder="Your E-mail" maxlength="50" class="validate">
<button name="email_btn" type="button" class="btn email-btn" style="width:174px;font-size:15px;">Send me Results!</button>
</div>
</form>
email_btn should be of type="submit" instead of type="button", so rather:
<button type="submit">Send me the results</button>
see here:
http://www.w3schools.com/tags/tag_button.asp
This should work with a submit Button!
(The extra php is to show that it works!)
<?php
if (isset($_POST['submitted'])) {
echo "form submitted";
}
?>
<form action="index.php" method="post" class="form-wrap">
<div class="loader-wrap">
<div class="loader-txt">
</div>
</div>
<div class="field-set url-field">
<input type="text" name="url" data-placeholder="Your Website URL" maxlength="50" class="validate">.
<button name="url_btn" type="button" class="btn url-btn">Scan My Site!</button>
</div>
<div class="field-set email-field">
<input type="text" name="USERNAME" data-placeholder="Your E-mail" maxlength="50" class="validate">
<button name="email_btn" type="button" class="btn email-btn" style="width:174px;font-size:15px;">Send me Results!</button>
<button name="submitted" type="submit">Send me the results</button> //Submit Button
</div>
</form>

Categories

Resources