1

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?

7
  • Encode the username and pass it through the URL. Commented Aug 19, 2014 at 8:28
  • can you please explain Commented 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. Commented 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. Commented Aug 19, 2014 at 8:33
  • 1
    How to use javascript to read data from url: stackoverflow.com/questions/979975/… Commented Aug 19, 2014 at 8:40

6 Answers 6

1

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

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

You can display the same using like, var UserName = '<?php echo $username; ?>'; $('#txtUserName').val(UserName);
0

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

You can't pass hidden inputs in a redirect. A redirect is always a GET.
login page is pure html page with login field an password field.
0

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>

Comments

0

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

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.