This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
How do I make a redirect in PHP?
(34 answers)
Closed 5 years ago.
i have a problem with PHP and HTML, I want a link to redirect to a PHP page for a login form, doing like so:
<p>Login</p>
redirect the browser to the file, but it shows just the code, without showing the form, is there something that i'm missing?
the link is referring to a PHP script, the code is this:
<?php
header("location:WebPage1.html");
include('login.php');
if(isset($SESSION['login.php'])){
header("location:login.php");
}
?>
<!doctype HTML>
<html>
<head>
<title>Login PC SHOP</title>
<a href="mystyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main">
<h1>Esegui il login al sito</h1>
<div id="login">
<h2>Login Form</h2>
<form action="" method="post">
<label>UserName :</label>
<input id="name" name="username" placeholder="username" type="text">
<label>Password :</label>
<input id="password" name="password" placeholder="**********"
type="password">
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
</div>
</div>
</body>
</html>
This is what i get when clicking the login link on the main webpage:
<HTML>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<title>
PC Shop - Home Page
</title>
</head>
<body>
<h1> PC Shop </h1>
<p>Login</p>
<table border=1>
<tr>
<td>
Carrello
</td>
<td>
Area Clienti
</td>
</tr>
</table>
</body>
</HTML>
Executing PHP is done by a server. When no server is running/installed your browser will most likely just show the contents of that file. You'll need something like WAMP (windows), XAMPP (linux) or MAMP (osx).
Related
This question already has answers here:
jquery mobile w/ php login form
(2 answers)
Closed 5 years ago.
am trying to submit a form from a jquery-mobile page to a php file for processing but whenever i press the submit button it displays an "Error Loading Page" dialog.
I have tried looking at the w3schools website form submission example and am pretty sure my code is the same.This is my code.
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Jquery Mobile</title>
<!-- Include meta tag to ensure proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Include jQuery Mobile stylesheets -->
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<!-- Include the jQuery library -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<!-- Include the jQuery Mobile library -->
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style>
.ui-content {
margin-top:150px;
margin-left:500px;
margin-right:500px;
}
/* For mobile screens */
#media screen and (max-width: 480px) {
.ui-content{
margin:0px;
}
</style>
</head>
<body>
<div data-role="page" id="chat">
<div data-role="header"><h1>Welcome to the Streamline Chat App</h1></div>
<div data-role="main" class="ui-content">
<h3>Select a username to continue</h3>
<form method="post" action="login.php">
<label for="username" >Username:</label>
<input type="text" id="username" name="username">
<input type="submit" data-inline="true" value="Submit">
</form>
</div>
</div>
</body>
</html>
login.php
<?php
$username = $_POST['username'];
echo $username;
?>
Am wondering if am doing something wrong. Please help me out. Both files are in the same directory
I got the answer from another post here
Just needed to add data-ajax="false" to the form tag
<form method="post" action="login.php" data-ajax="false">
<label for="username" >Username:</label>
<input type="text" id="username" name="username">
<input type="submit" data-inline="true" value="Submit">
</form>
Is this the way to write your PHP? I would like to know if I can use an external file to keep things seperated, as I like to be organised. Also do I need to store my entire content in the XAMPP folder in Windows(C:) or just the PHP files? Haven't been able to find a decent answer on these questions. Help greatly appreciated.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="pagestyling.css">
</head>
<body>
<?php
include('/path/to/file.php');
?>
//scripts go here
</body>
</html>
EDIT EXAMPLE:
<?php
//form validation code here
?>
<div id="content">
<form class="applyform" method="POST" action="">
<h3>Please fill in your application below.</h3>
<p>
<label>In-game username:</label>
<input name="username" type="text"></input>
<h6>*Including CAPITALISED letters (if you have it)</h6>
</p>
<p>
<label>Irl Nickname:</label>
<input name="nickname" type="text"></input>
<h6>(So we know what to call you)</h6>
</p>
<p>
<label>Game:</label>
<select name="selectgame">
<option value="Heroes of Atlan">Heroes of Atlan
<option value="Knights and Dragons">Knights and Dragons
</select>
<h6>(What game do you want to join us in?)</h6>
</p>
<p>
<label>Email Address:</label>
<input name="emailaddress" type="text"></input>
<h6>*Used for GroupMe and confirmation email.</h6>
</p>
<p>
<label>Level:</label>
<input name="charlevel" type="text"></input>
<h6>(Your main character level)</h6>
</p>
<p>
<label>Arena rank:</label>
<input name="arenarank" type="text"></input>
<h6>(E.g. Heroes of Atlan: (1) 3358 or K&D: RIBBON E)</h6>
</p>
<p>
<label>Referral code:</label>
<input name="refcode" type="text"></input>
<h6>(Knights and Dragons only, e.g. "XU5-CP3-SK9")</h6>
</p>
<h5>Please check that the information that you have entered is correct before proceeding.</h5>
<input id="submitbutton" name="applySubmit" type="submit" value="Submit"></input>
</form>
</div> <!-- end of content -->
make a php file like this
include_file.php
<?php
//some php code
?>
some html here
now you can include it in every page you require. like this
<?php
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="pagestyling.css">
</head>
<body>
<?php
include("include_file.php");
?>
</body>
</html>
you can also use include, require, require_once or include_once as per your requirement.
and learn tutorial
Usualy you would write for exempe the header in the seperate header.php file and then include it in your main file:
<?php include('header.php'); ?>
I am using Post method in my website. In my index.html file is the following code:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Heater Login</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<form method="post" action="login.php" class="login">
<p>
<label for="login">Username:</label>
<input type="text" name="login" id="login" value="John Appleseed">
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="4815162342">
</p>
<p class="login-submit">
<button type="submit" class="login-button">Login</button>
</p>
</form>
</body>
</html>
And in my login.php file is the following code:
<?php
echo($_POST['login']);
echo($_POST['password']);
?>
When I open html file, enter my credentials, click submit button it goes to php file end there's nothing.
Can you change this line of code with the new one Hope it will work
<button type="submit" class="login-button">Login</button>
<input type="submit" name="submit" value="Login">
And last I want that you copy whole code from the stackoverflow and use this code.Some times space may create a problem.
This problem occurs when you directly open from its file location try opening file from server
like if you're using xampp open localhost and then try.
This question already has answers here:
Reload the page on hitting back button
(6 answers)
Closed 9 years ago.
I'm making a website in which there is a login page and then the home page..
Now once I have logged in I want this to happen.
It should not go back to the login page when I click THE BROWSER BACK BUTTON.
It should refresh the home page jus like HOW FACEBOOK DOES..
I have checked and googled but I am not finding the answer...
I would really appreciate it if anyone helps me...
Thank You..
This is the login page.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>mindclik</TITLE>
<link rel="stylesheet" type="text/css" href="stylesheets\home.css">
<link rel="stylesheet" type="text/css" href="stylesheets/home.css">
</HEAD>
<BODY>
<div id="wrap">
<div id="main">
<div id ="left">
</br>
<h2>Login</h2>
<form id="login_form" action="home.php" method="post" >
<table >
<tr>
<td>
Email:
</td>
<td>
<input type="text" name="email" id="email" class="login_tb" >
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type=password name="pwd" id="pwd"" class="login_tb">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type=submit id="sub" value="SignIn">
</td>
</tr>
</table>
</form></div>
</div></div>
This is the homePage.php
<?php
$p_uname=$_POST['email'];
$p_pass=$_POST['pwd'];
$enc_pass=md5($p_pass);
?>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="stylesheets/home1.css">
</head>
<body>
<div id="wrap">
<div id="left_contain"> Friend List</div>
<div id="main"></div>
<div id="right_contain_top">Friend New Answers</div>
<div id="right_contain_bot">Questions From AOF</div>
</div>
</body>
</html>
You can set cookies once the user is authenticated. On successful login
setcookie("Valid", $user_name);
In the login page place this at the top.
<?php
if ($_COOKIE['Valid'] == $user_name ) {
header( 'Location: homepage.php' ) ;
}
?>
This hack would work. Change the file extension of login page to .php
I'm new to php and am trying to make a very simple two page form. Any help or guidance would be very appreciated!
Problem:
The second page does not run error validation when coming to it from the first page.
Both pages run error validation correctly URL's entered directly
Setup:
Page 1 one is HTML. It POSTS to Page2.
Page 2 is php and the data from Page 1 is stored in an input field
Live example:
http://www.linplusg.com/page1.html
In IE the Page 2 URL after coming from Page 1 looks to be incorrect:
http://www.linplusg.com/page1.html#/page2.php
In FF and Chrome the URL looks fine but I think there's a flicker/refresh happening.
Does something else happen besides just opening the page when doing a POST to a page? Does something value get stored the new fields? Am I doing the form action wrong? Dazed and confused...
Thank you so much for any help or suggestions. I've been searching around for answers all night and my brain feels like jello. It seems like I'm missing something simple?!
Page1 Code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>
</title>
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" href="css/my.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
</script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js">
</script>
<script>
$(document).ready(function(){
$("#initialForm").validate();
});
</script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="page1">
<div data-role="content">
<form id="initialForm" method="post" action="page2.php">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="textinput3">
Zip Code
</label>
<input name="zip" id="zip" maxlength=5 value="" type="text" class="required" />
</fieldset>
</div>
<input type="submit" data-theme="e" value="Submit" />
</form>
</div>
</div>
</body>
</html>
Page 2 code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>
</title>
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" href="css/my.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
</script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js">
</script>
<script>
$(document).ready(function(){
$("#fullForm").validate();
});
</script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="page1">
<div data-role="content">
<form id="fullForm" method="get" action="">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<input name="zip" id="zip" value="<?php echo $_POST["zip"]; ?>" type="" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="textinput3">
First Name
</label>
<input name="first_name" id="first_name" placeholder="" value="" type="text" class="required"/>
</fieldset>
</div>
<input type="submit" data-theme="e" value="Submit" />
</form>
</div>
</div>
</body>
</html>
To prevent this you need to specify data-ajax="false" in the form element in page1.
<form id="initialForm" method="post" action="page2.php" data-ajax="false">
see http://jquerymobile.com/test/docs/forms/forms-sample.html for more information.
Without the PHP code, I can just guess, but maybe it is because in the second form you have a method="get" instead of method="post", and in PHP you check the $_POST variable?
You could preserve the ajax transitions and still have your javascript execute on your second page by moving your script inside the div with the data-role "page".
See this answer here: https://stackoverflow.com/a/6428127/2066267