Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][MYSQL]kod php zapisany w mysql
Forum PHP.pl > Forum > Przedszkole
hostcom
Witam
tworze szaty htm do wysyłania w mailach zapisane w bazie, ale nie wiem jak rozwiazac to z kodem php żeby przegladarka go interpretowała
przykład zapisanego kodu w mysql
  1. <?php
  2. <img src='".$site_config['SITEURL']."/themes/default/images/blank.gif' alt='' style='display: block;' height='24' width='1'>
  3. ?>

po poraniu zawartości tabeli kod php jest wyświetlany jak zwykły text. jest na to jakies rozwiazanie?
Marq
To nie przeglądarka interpretuje kod php, tylko serwer, a właściwie to intepreter PHP. Przeglądarka dostaje czysty kod HTML od serwera.
hostcom
ale jest mozliwe że po pobraniu części kodu php z tabeli serwer zinterpretował go jak php a nie jako text?
bregovic
Tak, to jest możliwe używając eval" title="Zobacz w manualu PHP" target="_manual. Ale to co pokazujesz to zwykły html (w dodatku nie poprawny)? W dodatku eval to zło poczęte. Może wytłumacz trochę lepiej twój problem?
hostcom
w moim skrypcie
  1. <?
  2.  
  3. require_once("backend/functions.php");
  4. dbconn(false);
  5. loggedinonly();
  6.  
  7.  
  8. if ($site_config['INVITEONLY']== false){
  9. stdhead("Invite");
  10. begin_frame("Invite");
  11. echo "<BR><BR>Invites are disabled, please use the register link.<BR><BR>";
  12. end_frame();
  13. stdfoot();
  14. }
  15.  
  16. $res = mysql_query("SELECT COUNT(*) FROM users") or sqlerr(__FILE__, __LINE__);
  17. $arr = mysql_fetch_row($res);
  18.  
  19.  
  20.  
  21. if($CURUSER["invites"] == 0)
  22. show_error_msg("Sorry","No invites!");
  23.  
  24. $mess= unesc($_POST["mess"]);
  25.  
  26. if (!$mess)
  27. show_error_msg("Error", "You must enter a message!");
  28.  
  29. if (!mkglobal("email"))
  30. die();
  31.  
  32.  
  33. function barkmsg($msg) {
  34. stdhead();
  35. begin_frame("ERROR");
  36. echo "<BR><BR>Invite Failed!<BR><BR>";
  37. echo $msg;
  38. end_frame();
  39. stdfoot();
  40. }
  41.  
  42.  
  43. if (!validemail($email))
  44. show_error_msg("Error", "That doesn't look like a valid email address.");
  45.  
  46. // check if email addy is already in use
  47. $a = (@mysql_fetch_row(@mysql_query("select count(*) from users where email='$email'"))) or die(mysql_error());
  48. if ($a[0] != 0)
  49. show_error_msg("Error", "The e-mail address $email is already in use.");
  50.  
  51. $secret = mksecret();
  52. $editsecret = mksecret();
  53. $username = rand();
  54. $ret = mysql_query("INSERT INTO users (username, secret, editsecret, email, status, invited_by, added) VALUES (" .
  55. implode(",", array_map("sqlesc", array($username, $secret, $editsecret, $email, 'pending', $CURUSER["id"]))) .
  56. ",'" . get_date_time() . "')");
  57. if (!$ret) {
  58. if (mysql_errno() == 1062)
  59. show_error_msg("Error", "Username already exists!");
  60.  
  61. }
  62. $id2 = $CURUSER["id"];
  63. $invites = $CURUSER["invites"]-1;
  64. $invitees = $CURUSER["invitees"];
  65. $invitees2 = "$id $invitees";
  66. $ret2 = mysql_query("UPDATE users SET invites='$invites', invitees='$invitees2' WHERE id = $id2");
  67.  
  68. $username=$CURUSER["username"];
  69. $psecret = md5($editsecret);
  70. $headers  = 'MIME-Version: 1.0' . "r\n";
  71. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "r\n";
  72. $message = ($html ? strip_tags($mess) : $mess);
  73. $siteurl=$site_config['SITEURL'];
  74. $ret3 = mysql_query("SELECT * FROM mailthemes");
  75. $them = mysql_fetch_array($ret3);
  76. $header= $them["header"];
  77. eval($header == "$siteurl = \"$siteurl\";");
  78. $body = "$header";
  79. mail($email, $siteurl, $body, $headers);
  80.  
  81. header("Refresh: 0; url=account-confirm-ok.php?type=invite&email=" . urlencode($email));
  82.  
  83.  
  84. ?>

w lini
  1. <?php
  2. $body= "$header"
  3. ?>

jest wyswietlany text z mysql
czyli ten;
  1. <b>Zosta&para;eś zaproszony do naszej społeczności</b></td>
  2. <td class='fcapend'><img src='".$site_config['SITEURL']."/themes/default/images/blank.gif' alt='' style='display: block;' height='24' width='1'></td>
  3. <td class='fcapmain'><img src='".$site_config['SITEURL']."/themes/default/images/blank.gif' alt='' style='display: block;' height='24' width='1'></td>
  4. <td class='ftr'><img src=".$site_config['SITEURL']."/themes/default/images/blank.gif' alt='' style='display: block;' height='24' width='9'></td></tr></tbody></table>
  5. <table cellpadding='0' cellspacing='0'><tbody><tr><td class='fml'><img src='".$site_config['SITEURL']."/themes/default/images/blank.gif' alt='' style='display: block;' height='8' width='9'></td>
  6. <td class='fmmain'>You have been invited to ".$site_config['SITEURL']." by ".$username.". They have
  7. specified this address (".$email.") as your email. If you do not know this person, please ignore this email. Please do not reply.
  8. Message:
  9. -------------------------------------------------------------------------------
  10. ".$message."
  11. -------------------------------------------------------------------------------
  12.  
  13. This is a private site and you must agree to the rules before you can enter:
  14.  
  15. $siteurl/rules.php
  16.  
  17. ".$site_config['SITEURL']."/faq.php
  18.  
  19.  
  20. To confirm your invitation, you have to follow this link:
  21.  
  22. $siteurl/confirminvite.php?id=".$id."&secret=".$psecret."
  23.  
  24. After you do this, you will be able to use your new account. If you fail to
  25. do this, your account will be deleted within a few days. We urge you to read
  26. the RULES and FAQ before you start using ".$site_config['SITEURL'].".
  27. <BR><BR></td><td class='fmr'>
  28. <img src=$siteurl/themes/default/images/blank.gif' alt='' style='display: block;' height='8' width='9'></td></tr></tbody></table><table cellpadding='0' cellspacing='0'><tbody><tr><td class='fbl'>
  29. <img src=$siteurl/themes/default/images/blank.gif' alt='' style='display: block;' height='10' width='9'></td><td class='fbm'>
  30. <img src=$siteurl/themes/default/images/blank.gif' alt='' style='display: block;' height='10' width='3'></td><td class='fbr'>
  31. <img src=$siteurl/themes/default/images/blank.gif' alt='' style='display: block;' height='10' width='9'></td></tr></tbody></table></td></tr></tbody></table><BR>
  32. </TR>
  33. </TABLE></td></tr></table>
  34.  
  35. <BR><BR><BR>
  36. </BODY>
  37. </HTML>

Ja chciałbym żeby serwer po popraniu z bazy interpretował php czyli to: $siteurl $site_config['SITEURL']."/
bregovic
Ok. Znacznie lepiej na dłuższą metę będzie ci użyć znaczników. Zamień te zmienne na jakieś niepowtarzalne znaczniki, np ###ID### i podmieniaj dzięki str_replace" title="Zobacz w manualu PHP" target="_manual. Oczywiście możesz też to przelecieć eval" title="Zobacz w manualu PHP" target="_manual - ale wtedy musisz przy każdej zmiennej "wejść" w tryb php (używając <?php ?>). Czyli np biorąc pierwszą linię ze zmienną:
  1. <td class="fcapend"><img src="<?php echo $site_config['SITEURL'] ?>/themes/default/images/blank.gif" alt="" style="display: block;" height="24" width="1"></td>
hostcom
Dziekuje za pomoc


PS a możesz napisać o co ci chodziło
Cytat
W dodatku eval to zło poczęte
erix
Cytat
PS a możesz napisać o co ci chodziło


http://stackoverflow.com/questions/86513/w...tion-a-bad-idea

Wiem, że to o JavaScript, ale powody są bardzo podobne.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.