I have a php page which displays certain profile data like Name,Username,Phone,Addres etc which were passed as params in url.Now after saving those details the page is being redirected to an html login page where I need to display the Username value in the text field for the Username.I tried to pass the username from php to html in many ways but in vain.By what means can i pass the username from the php page to html login page and display it in Username text field?
-
Encode the username and pass it through the URL.Jenz– Jenz2014-08-19 08:28:50 +00:00Commented Aug 19, 2014 at 8:28
-
can you please explainuser3363475– user33634752014-08-19 08:31:06 +00:00Commented Aug 19, 2014 at 8:31
-
You can't pass variables to a static HTML page. If you pass the variables in the URL, either the page has to be created using a script, or it has to have Javascript that uses the parameters.Barmar– Barmar2014-08-19 08:31:35 +00:00Commented Aug 19, 2014 at 8:31
-
How to pass the data via url and fetch the sane in html page.The second page is pure html.So is it possible to decode and retrieve the same.user3363475– user33634752014-08-19 08:33:02 +00:00Commented Aug 19, 2014 at 8:33
-
1How to use javascript to read data from url: stackoverflow.com/questions/979975/…ODaniel– ODaniel2014-08-19 08:40:59 +00:00Commented Aug 19, 2014 at 8:40
6 Answers
Use a php Site for login and than use this code at your registerscript (php) (be sure this is the first thing send to the client no echo before this)
header("LOCATION: http://www.something.com?username=walter&secoundusername=white");
In your login page you can access the data with
if(isset($_GET('username'))){
$username = $_GET('username');
}...
I hope this works for you.
1 Comment
your question is not too clear, however if the html login page is just a static page, i don't see how your request could be achieved.
If instead it's a php generated html page, then you may pass the variable via a hidden input field for example.
2 Comments
GET.You can pass username as parameter in URL like
http://yoursite.com/login.html?username=abc
and in login.html use javascript to get the url parameter and assign it to textbox.
function getParamURL(param) {
return decodeURIComponent((new RegExp('[?|&]' + param + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
var username = getParamURL('username');
document.getElementById("username").value= username;
suppose your textbox id is username then it should assign it to that text box
Comments
Here is the login page
<?php
if($_POST)
{
include("Connect.php");
$Username=$_POST["Username"];
$Password=$_POST["Password"];
$Query="select Username from user where username='$Username' and password='$Password' LIMIT 1";
$Result=mysql_query($Query);
while($R=mysql_fetch_array($Result))
{
header("location:main.html?username='$R[0]'");
}
}
?>
<form action="<?=$_SERVER['PHP_SELF'] ?>" method="POST">
<input type="text" name="Username">
<input type="text" name="Password">
<input type="submit"/>
</form>
Here is how you could retrieve the page.The variable needs to be a php page
<html>
<p>Welcome</p> <?php
$Name=$_GET["username"];
echo $Name;
?>
</html>