943,868 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 4033
  • PHP RSS
Sep 26th, 2008
0

How to return a php variable, to a html file which can be use in html file as javascr

Expand Post »
In php file I write ;
echo "<meta http-equiv=Refresh content=0;url=login.html>";

Here i load a login.html file. Along this i want to pass a php variable(suppose $nflag) content to login.html file, so that i can use it in javascript within login.html file. Please Help me.
Reputation Points: 10
Solved Threads: 2
Light Poster
mohammed2raja is offline Offline
30 posts
since Sep 2008
Sep 26th, 2008
0

Re: How to return a php variable, to a html file which can be use in html file as javascr

The best way to pass short variables such as a page title is using url variables so use the following code:

First page before redirect.
php Syntax (Toggle Plain Text)
  1. // Note it redirects to a php page.
  2. echo "<meta http-equiv=Refresh content=0;url=login.php?nflag=".$nflag.">";

Login.php page
html Syntax (Toggle Plain Text)
  1. <?
  2. $nflag=$_GET['nflag'];
  3. ?>
  4. <html><body>
  5. The variable passed on is <? echo $nflag; ?>.
  6. </body></html>
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Sep 26th, 2008
0

Re: How to return a php variable, to a html file which can be use in html file as javascr

Thank u.
Where the variable
nflag
is stored?
Reputation Points: 10
Solved Threads: 2
Light Poster
mohammed2raja is offline Offline
30 posts
since Sep 2008
Sep 26th, 2008
0

Re: How to return a php variable, to a html file which can be use in html file as javascr

In my example of login.php, the variable was stored in $nflag with the use of the first 3 lines making it $nflag. Also the code $_GET['nflag'] retrieves the variable named nflag from the url bar.

Just in case if you are confused or are wondering on how the example I wrote for login.php works I shall explain each line. As most php programmers would know, lines 1 and 3 are the opening and closing of the php code. In line 2, the variable $nflag is being assigned to be just like the previous page so you wouldn't need to use an array to call the value and for good looks. Also below will work just the same:
html Syntax (Toggle Plain Text)
  1. <html><body>
  2. The variable passed on is <? echo $_GET['nflag']; ?>.
  3. </body></html>
So the line in the middle of the example above is basically telling the server to 'get' the variable 'nflag' from the url bar and to echo/display it.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How will i solve this stuff?
Next Thread in PHP Forum Timeline: Where _GET[] array is formed?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC