Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: Funebrer0 en 11 Septiembre 2015, 05:02 am



Título: [Resuelto] Ayuda con función require()
Publicado por: Funebrer0 en 11 Septiembre 2015, 05:02 am
Hola. Estoy aprendiendo PHP lo cual me resulta relativamente fácil porque he visto C++ en la facultad, pero en la parte de funciones tengo un problema: A la hora de utilizar la función require() es como si no hiciera nada. Les dejo los códigos a ver si me pueden ayudar a ver en donde le estoy errando. Gracias.

HOME.HTML
Código
  1. <?php require('header.php'); ?>
  2.  
  3.    <!-- Page Content -->
  4.    <p>Welcome to the home of TLA Consulting. Please take some time to get to know us.</p>
  5.    <p>We specialize in serving your business needs and hope to hear from you soon.</p>
  6.  
  7. <?php require('footer.php'); ?>
  8.  

HEADER.PHP
Código
  1. <!DOCTYPE html>
  2.  <head>
  3.    <meta charset="utf-8">
  4.    <title>TLA Consulting Pty Ltd</title>
  5.    <style>
  6.      h1{color:white; font-size:24pt; text-align:center; font-family:arial,sans-serif; font-weight:bold}
  7.      .menu{color:white; font-size:12pt; text-align:center; font-family:arial,sans-serif}
  8.      td{background:black}
  9.      p{color:black; font-size:12pt; text-align: justify; font-family: arial,sans-serif; font-weight:bold}
  10.      p.foot{color:white; font-size:9pt; text-align:center; font-family:arial,sans-serif; font-weight:bold}
  11.      a:link,a:visited,a:active{color:white}
  12.    </style>
  13.  </head>
  14.  <body>
  15.    <!-- Page Header -->
  16.    <table width="100%" cellpadding="12" cellspacing="0" border="0">
  17.      <tr bgcolor="black">
  18.        <td align="left"><img src="img/logo.gif" alt="TLA logo" height="70" width="70"></td>
  19.        <td><h1>TLA Consulting</h1></td>
  20.        <td align="right"><img src="img/logo.gif" alt="TLA logo" height="70" width="70"></td>
  21.      </tr>
  22.    </table>
  23.    <!-- Menu -->
  24.    <table width="100%" bgcolor="white" cellpadding="4" cellspacing="4">
  25.      <tr>
  26.        <td width="25%">
  27.          <img src="img/logo.gif" alt="" height="20" width="20">
  28.          <span class="menu">Home</span>
  29.        </td>
  30.        <td width="25%">
  31.          <img src="img/logo.gif" alt="" height="20" width="20">
  32.          <span class="menu">Contact</span>
  33.        </td>
  34.        <td width="25%">
  35.          <img src="img/logo.gif" alt="" height="20" width="20">
  36.          <span class="menu">Services</span>
  37.        </td>
  38.        <td width="25%">
  39.          <img src="img/logo.gif" alt="" height="20" width="20">
  40.          <span class="menu">Site Map</span>
  41.        </td>
  42.      </tr>
  43.    </table>
  44.  

FOOTER.PHP
Código
  1. <!-- Page Footer -->
  2.    <table width="100%" bgcolor="black" cellpadding="12" border="0">
  3.      <tr>
  4.        <td>
  5.          <p class="foot">&copy; TLA Consulting Pty Ltd.</p>
  6.          <p class="foot">Please see our <a href="legal.php">Legal Information page</a></p>
  7.        </td>
  8.      </tr>
  9.    </table>
  10.  </body>
  11. </html>
  12.  

Mod: Temas sobre PHP van al subforo de PHP.


Título: Re: [PHP] Ayuda con función require()
Publicado por: engel lex en 11 Septiembre 2015, 05:50 am
la pagina no te da errores? te aseguraste que el nombre sea identico? (case sensitive)


Título: Re: [PHP] Ayuda con función require()
Publicado por: Funebrer0 en 11 Septiembre 2015, 06:16 am
Ningún error me tira, solo muestra el contenido que escribo en el archivo home.html, sin mostrar los dos archivos que incluí con require.
Tienen el mismo nombre los archivos.


Título: Re: [PHP] Ayuda con función require()
Publicado por: engel lex en 11 Septiembre 2015, 06:24 am
en el codigo fuente de la pagina cuando se carga, que hay? solo el contenido que pusiste sin las etiquetas php?


Título: Re: [PHP] Ayuda con función require()
Publicado por: DeMoNcRaZy en 11 Septiembre 2015, 08:59 am
¿La página te aparece en blanco?

Revisa la ruta del require, borra el cache de tu navegador.

De igual modo prueba así:

Header.php
Código
  1. <!DOCTYPE html>
  2. <html>
  3.  <head>
  4.    <meta charset="utf-8">
  5.    <title>TLA Consulting Pty Ltd</title>
  6.    <style>
  7.      h1{color:white; font-size:24pt; text-align:center; font-family:arial,sans-serif; font-weight:bold}
  8.      .menu{color:white; font-size:12pt; text-align:center; font-family:arial,sans-serif}
  9.      td{background:black}
  10.      p{color:black; font-size:12pt; text-align: justify; font-family: arial,sans-serif; font-weight:bold}
  11.      p.foot{color:white; font-size:9pt; text-align:center; font-family:arial,sans-serif; font-weight:bold}
  12.      a:link,a:visited,a:active{color:white}
  13.    </style>
  14.  </head>
  15.  <body>
  16.    <!-- Page Header -->
  17.    <table width="100%" cellpadding="12" cellspacing="0" border="0">
  18.      <tr bgcolor="black">
  19.        <td align="left"><img src="img/logo.gif" alt="TLA logo" height="70" width="70"></td>
  20.        <td><h1>TLA Consulting</h1></td>
  21.        <td align="right"><img src="img/logo.gif" alt="TLA logo" height="70" width="70"></td>
  22.      </tr>
  23.    </table>
  24.    <!-- Menu -->
  25.    <table width="100%" bgcolor="white" cellpadding="4" cellspacing="4">
  26.      <tr>
  27.        <td width="25%">
  28.          <img src="img/logo.gif" alt="" height="20" width="20">
  29.          <span class="menu">Home</span>
  30.        </td>
  31.        <td width="25%">
  32.          <img src="img/logo.gif" alt="" height="20" width="20">
  33.          <span class="menu">Contact</span>
  34.        </td>
  35.        <td width="25%">
  36.          <img src="img/logo.gif" alt="" height="20" width="20">
  37.          <span class="menu">Services</span>
  38.        </td>
  39.        <td width="25%">
  40.          <img src="img/logo.gif" alt="" height="20" width="20">
  41.          <span class="menu">Site Map</span>
  42.        </td>
  43.      </tr>
  44.    </table>
  45.  
  46.    <?php require('footer.php'); ?>
  47.  
  48.   </body>
  49. </html>

Footer.php
Código
  1. <table width="100%" bgcolor="black" cellpadding="12" border="0">
  2.      <tr>
  3.        <td>
  4.          <p class="foot">&copy; TLA Consulting Pty Ltd.</p>
  5.          <p class="foot">Please see our <a href="legal.php">Legal Information page</a></p>
  6.        </td>
  7.      </tr>
  8.    </table>


Y luego por último el archivo Home.html cámbialo por index.php
y escribes dentro:

Código
  1. <?php require('header.php'); ?>
  2.  

Prueba así como te dije, copia el código y nos comentas.

Saludos.


Título: Re: [PHP] Ayuda con función require()
Publicado por: Funebrer0 en 12 Septiembre 2015, 01:34 am
Problema solucionado. Solo tenia que guardar el nombre de la web "principal" como .php en vez de .html .
Gracias por la ayuda.