0

How to pass the php variables from dynamically created HTML page to next php file. For Example. I have the following php code

<?php
 session_start();
 $uid=$_SESSION['uid'];
 $doc=new DOMDocument('1.0');
$doc->loadHTML("
                     <html>
                    <head>
                    </head>
                  <body>
                  <a href='comments.php?id=`$uid`'> comments</a>
                  </body>   
                  </html>
               ");
     echo 'wrote:'. $doc->savedHTMLFile("/home/user/project1/test1.html"). 'bytes';

?>

Now when I see dynamically created HTML page, it just shows me the following code with .html extension; so how can I pass the php variable from this page to next file:

                    <html>
                    <head>
                    </head>
                  <body>
                  <a href='comments.php?id=`$uid`'> comments</a>
                  </body>   
                  </html>
1
  • dynamically created page has .HTML extenstion; so is it possible to pass a php variable from HTML page? and how to make changes to make it work ? Commented Apr 8, 2014 at 6:12

4 Answers 4

1

try to replace

<a href='comments.php?id=`$uid`'>

to

<a href='comments.php?id=$uid'>
Sign up to request clarification or add additional context in comments.

Comments

0

try this... Your mistake is here 'comments.php?id=$uid' is string no php code use correct like this 'comments.php?id=".$uid."'.

<?php
session_start();
$uid = $_SESSION['uid'];
$doc = new DOMDocument('1.0');
$doc->loadHTML("
                <html>
                <head>
                </head>
                  <body>
                  <a href='comments.php?id=".$uid."'> comments</a>
                  </body>
                  </html>
               ");
echo 'wrote:' . $doc->savedHTMLFile("/home/user/project1/test1.html") . 'bytes';
?>

Comments

0

Basically, you can use $_GET[''] method to do it. You just insert it into the URL, but I think, this will make the site vulnerable to SQL Injection.

Comments

0

remove back ticks(`) around $uid or use this code

<?php
 session_start();
 $uid=$_SESSION['uid'];
 $doc=new DOMDocument('1.0');
 $doc->loadHTML("
                     <html>
                    <head>
                    </head>
                  <body>
                  <a href='comments.php?id=".$uid."> comments</a>
                  </body>   
                  </html>
               ");
     echo 'wrote:'. $doc->savedHTMLFile("/home/user/project1/test1.html"). 'bytes';

?>

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.