SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating PHP File for Repeated Content

    I'm not sure if this is where I should put it as I'm just new here. But I just want to know if it is possible to create a .php file for the repeated content? An example would be, if I want to change the promo date of a certain coupon in the index and would like that change to take effect to all of the pages of the website by only editing the index page, how can I do it? Is it possible to do it in a .php file?

    What I want is to lessen the time of editing each page and just edit the .php file instead of going through all of the 50+ pages of the website.

    If this is possible, how can I do that and which particular code should I use?

    I hope this question makes sense.

    I really need help on this matter so any suggestions would be greatly appreciated.

  2. #2
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hope someone could help me on this. I really need to learn more about this as I'm trying to work on this page. I'm slowly learning PHP and I know that I still need to know more. This is somewhat complicated for me.

  3. #3
    SitePoint Enthusiast rajeev13's Avatar
    Join Date
    Nov 2012
    Location
    New Delhi,India
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mpage109 View Post
    I'm not sure if this is where I should put it as I'm just new here. But I just want to know if it is possible to create a .php file for the repeated content? An example would be, if I want to change the promo date of a certain coupon in the index and would like that change to take effect to all of the pages of the website by only editing the index page, how can I do it? Is it possible to do it in a .php file?

    What I want is to lessen the time of editing each page and just edit the .php file instead of going through all of the 50+ pages of the website.

    If this is possible, how can I do that and which particular code should I use?

    I hope this question makes sense.

    I really need help on this matter so any suggestions would be greatly appreciated.
    Just Break the page into chunks like : header,footer ,center ,a separate php page.
    Include them to build a webpage, so u have change only these files.
    u can also call a function to show the promocode on ur site ,where function will be in another php page.

  4. #4
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rajeev13 View Post
    Just Break the page into chunks like : header,footer ,center ,a separate php page.
    Include them to build a webpage, so u have change only these files.
    u can also call a function to show the promocode on ur site ,where function will be in another php page.
    Thank you rajeev13 for your fast reply. But may I know how I will be able to break the pages in chunks? What code should I use? I'm really new to PHP and I am really not that confident to work on these codes.

  5. #5
    SitePoint Enthusiast rajeev13's Avatar
    Join Date
    Nov 2012
    Location
    New Delhi,India
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mpage109 View Post
    Thank you rajeev13 for your fast reply. But may I know how I will be able to break the pages in chunks? What code should I use? I'm really new to PHP and I am really not that confident to work on these codes.
    let say we have a index.php that shows the default page .look out below the sample code :
    index.php
    Code:
    <?
    session_start();
    include_once('includes/headerData.php');
    include_once('style.css');
    ?>
    
    </head>
    <body>
    <?
    include_once('includes/header.php');
    ?>
    	<div id="center" > 
                
            </div>
          
          
          
       <? include_once('includes/footer.php');?>
    	
    	</body>
    </html>
    headerData.php

    Code:
    <html>
    <head>
    <script type="text/JavaScript"></script>
    <link href='http://fonts.googleapis.com/css?family=Chela+One|Finger+Paint|Montserrat+Subrayada|Cherry+Swash&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
    header.php

    Code:
    <? 
    session_start();
    
    ?>
    <div id="header">
    			<div id="h1">
                                <a href="index.php"> <h2 id="h1" align="center">Sample web page</h2></a>
    			</div>	
     </div>
    footer.php
    Code:
    
    <div id="footer" align="center" >&#169 rajeev ranjan </div>

  6. #6
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What if there's only index.html in the file? How should I start on the index.php file?

  7. #7
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To keep this really simple, you could create a php page, say 'updates.php', with just the data you want to update regularly,e.g.

    PHP Code:
    <?php
    $promo_date 
    '15FEB13';
    $other_item 'other'//etc. etc.
    ?>
    Then in all the pages that require that info, add the line:

    PHP Code:
    include('updates.php'); 
    Then those variables and their values will be available in your other pages.
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  8. #8
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 2ndmouse View Post
    To keep this really simple, you could create a php page, say 'updates.php', with just the data you want to update regularly,e.g.

    PHP Code:
    <?php
    $promo_date 
    '15FEB13';
    $other_item 'other'//etc. etc.
    ?>
    Then in all the pages that require that info, add the line:

    PHP Code:
    include('updates.php'); 
    Then those variables and their values will be available in your other pages.
    Thank you 2ndmouse for this very simple code and explanation. I kind of understand it now a little.

    So on that second code, will I just put this code "include('updates.php'); " anywhere in each of the html page of the website? Of course in the location where I want that updates.php to appear in the webpage. Is that it?

  9. #9
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. To use php code in your pages, the pages must be page.php not page.html

    For example:

    If your index page is index.html you can add the following code above your html :

    PHP Code:
    <?php
    include('updates.php');
    ?>
    <Your html here>
    Then rename the page index.php
    Your server should load that automatically if its directory is loaded in the browser.

    You can use the included values in your html by inserting <?php echo $promo_date ?> where ever you need that value to appear.

    Hope that helps
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  10. #10
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I renamed the index.html to index.php but it's no longer opening. What wrong thing must I have done here?

  11. #11
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you add the php code to the top of that page?

    PHP Code:
    <?php 
    include('updates.php'); 
    ?>
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  12. #12
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I did but I'm not sure if I did it correctly. Here it is....

    php_include.png

  13. #13
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems your image will take a while for approval.

    Your index.php file should look something like this:

    PHP Code:
    <?php
    include('updates.php');
    ?>
    <html><head>
    </head><body>
    Your content
    </body></html>
    If that fails, create a file named phpinfo.php, insert the following code to that page:

    PHP Code:
    <?php
    // Show all information, defaults to INFO_ALL
    phpinfo();
    ?>
    Upload the page to your site and run it in your browser. You should see displayed all current PHP settings on your server. If you don't get this displayed, then it probably means that PHP is not installed on your server.
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  14. #14
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know what happened but when I opened the homepage I got this message on my screen: Parse error: syntax error, unexpected T_STRING in /home/content/08/6277108/html/airconditioningokc/updates.php on line 6

    I just followed your instruction but I still get errors. So how do I install PHP in my server?

  15. #15
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That looks like a php error, so I guess php must be installed already. Did you run the phpinfo file yet?

    The image of your code is still pending approval, so I haven't yet seen your file contents. Can you paste your file contents between [PHP] tags in your next post here, so that I can see what you have there.

    Meanwhile, here's one to try:

    First, create the file: updates.php with the code below and upload to your server.

    PHP Code:
    <?php
    $promo_date 
    '15 FEB 2013';
    ?>
    Then create a file: test.php and upload it to your server in the same directory as updates.php.

    Code for test.php:

    PHP Code:
    <?php 
    include('updates.php'); 
    ?> 
    <html><head> 
    </head><body> 
    <?php echo $promo_date?> 
    </body></html>
    Then run test.php in your browser - it should display the promo date
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  16. #16
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok it displayed the promo date correctly. This is what showed in the test.php page:

    PHP Code:
    15 FEB 2013 

    And this is what's in that pending image:

    PHP Code:
    <?php
    include('updates.php');
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    But I already changed it with:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <?php
    include('updates.php');
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    and then phpinfo file but this error message appeared:

    PHP Code:
    Parse errorsyntax errorunexpected T_STRING in /home/content/08/6277108/html/airconditioningokc/updates.php on line 6 

  17. #17
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mpage109 View Post

    and then phpinfo file but this error message appeared:

    PHP Code:
    Parse errorsyntax errorunexpected T_STRING in /home/content/08/6277108/html/airconditioningokc/updates.php on line 6 
    The error is in file: updates.php

    What have you got in that file?
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  18. #18
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh this was what's in the updates.php file:

    PHP Code:
    <?php 
    $promo_date 
    '15 FEB 2013'
    $analytics_code '<script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['
    _setAccount', 'UA-20639892-2']);
      _gaq.push(['
    _trackPageview']);

      (function() {
        var ga = document.createElement('
    script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('
    https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        
    var document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gas);
      })();

    </script>'
    ?>
    I thought that I could also include the analytics code there. Because my goal was to also put the analytics code in every page through a php file so I thought this was ok.

  19. #19
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that shouldn't be a problem.

    You've forgotten the semi-colon at the end of your string

    </script>'
    ?>

    should be:

    </script>';
    ?>

    That's what php is complaining about.
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  20. #20
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK so this is exactly what put in the updates.php

    PHP Code:
    <?php
    $coupon_date 
    'Offer expires last day of October 2013! Limit 1 per Client per year. Not valid with other offers.';
    $analytics_code '<script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['
    _setAccount', 'UA-20639892-2']);
      _gaq.push(['
    _trackPageview']);

      (function() {
        var ga = document.createElement('
    script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('
    https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        
    var document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gas);
      })();

    </script>';
    ?>
    ...then edited the above portion of the index.php with this:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <?php
    include('updates.php');
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    ...and also edited the portion of the page where I wanted these to be placed:

    PHP Code:
    <?php echo $analytics_code ?>

    and

    <?php echo $coupon_date ?>

    ...then uploaded both updates.php and index.php, yet I still get this error message:

    PHP Code:
    Parse errorsyntax errorunexpected T_STRING in /home/content/08/6277108/html/airconditioningokc/updates.php on line 6 
    What mistake must I have done?

  21. #21
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh is that it? Ok let me try it again and update you. Thank you very much. I'm really learning here.

  22. #22
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP is objecting to the string contents. In your google script, I've replaced all the inner single-quotes with double-quotes, as follows:

    PHP Code:
    <?php
    $promo_date 
    '15FEB13';
    $analytics_code '<script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(["_setAccount", "UA-20639892-2"]);
      _gaq.push(["_trackPageview"]);

      (function() {
        var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
        ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
        var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>'
    ;
    ?>
    See how the strings in the [PHP] tags are all red now - an unbroken string. It should run ok now.
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  23. #23
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! This is great! It's working real fine now! Thanks a bunch!!!

    So my next step now is to implement that command to all of the pages of the website. How do I do that? Should I rename all html extension pages with .php then?

  24. #24
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, add

    PHP Code:
    <?php 
    include('updates.php'); 
    ?>
    to all the pages that need the updates info and save them as .php files.

    Then in your html, insert the php values:

    HTML Code:
    <html><head><title></title>
    <?php echo $analytics_code ?> <!--assuming the google javascript should be inside the <head> tags-->
    </head>
    <body>
    <?php echo $coupon_date ?> <!-- this can be in the body like this or as a value in a form or in the cell of a table, anywhere really. -->
    </body></html>
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  25. #25
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should I also include these comments:

    <!--assuming the google javascript should be inside the <head> tags-->

    and

    <!-- this can be in the body like this or as a value in a form or in the cell of a table, anywhere really. -->

    or even without those comments it's fine?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •