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 Aug 19 '14 at 08:28
-
can you please explain – user3363475 Aug 19 '14 at 08: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 Aug 19 '14 at 08: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 Aug 19 '14 at 08:33
-
Yes javascript is allowed in both the pages.wHERE I GOT STRUCK IS HOW TO PASS THE VALUE FROM PHP PAGE TO HTML PAGE – user3363475 Aug 19 '14 at 08:36
-
hOW TO PASS VALUE VIA JAVASCRIPT @ bARMAR – user3363475 Aug 19 '14 at 08:37
-
1How to use javascript to read data from url: http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter – ODaniel Aug 19 '14 at 08:40
6 Answers
if you don't use any PHP Framework then you can save it by session or cookies. Then on login page you can get it and show

- 11
- 1
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.

- 86
- 1
- 9
-
You can display the same using like, var UserName = ''; $('#txtUserName').val(UserName); – Emma Aug 19 '14 at 08:43
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.

- 104
- 1
- 13
-
You can't pass hidden inputs in a redirect. A redirect is always a `GET`. – Barmar Aug 19 '14 at 08:32
-
You could use the fputs php function to create a html page
<?php
$fp = fopen("file.html", 'w+');
fputs($fp, "YOUR HTML CODE");
fputs($fp, "YOUR HTML CODE");
fputs($fp, "$variable");
fclose($fp);
?>
<a href='file.html'>Link</a>

- 23
- 4
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

- 3,664
- 2
- 23
- 38
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>

- 111
- 1
- 13