Web Analytics Made Easy -
StatCounter Having a Link Change With the Date - CodingForum

Announcement

Collapse
No announcement yet.

Having a Link Change With the Date

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Having a Link Change With the Date

    I have a link on my site that points to a page my client has asked to change daily. Basically, it is a report that is updated each morning and posted first thing. The format of the link is http://www.domain.com/presentations/.../ppt.asp?pic=1 As you can see, it points to a powerpoint presentation. The format of the URL stays the same, so I first suspected I required javascript code to determine the year, month and date and then insert it into the link in some manner. I was later told that I would need to check and see if the page was actually created before the link is made and that this should be in PHP so as to check the server time/date and not the client time/date.

    The site is done with a PHP CMS, and while I'm slowly learning the PHP ropes, this is a bit beyond me. I would greatly appreciate any help that could be offered.

  • #2
    on your page, maybe

    $file = date("m-d-y").'.php';
    if(file_exists($file)){
    include $file;
    } else {
    echo 'Todays presentation has not been posted yet.';
    }

    then just make a page called (month)-(day)-(year).php every morning.


    hope this helps
    php & asp tutorials - the birthplace - biorust - photoshop and web technologies

    Comment


    • #3
      The IF statement looks like something I could use, but I will not be able to create a new page every morning, as this site is being handed off to another department once I am complete. I have a Javascript solution, but not a PHP one.

      Thanks for the tips though.

      Comment


      • #4
        post the js code i might be able to translate it (or parts of it) into php and leave the bits that i cant
        php & asp tutorials - the birthplace - biorust - photoshop and web technologies

        Comment


        • #5
          Thanks for the offer. Here's the JS code:

          Code:
          Date.prototype.getMonthString = function() {
          	var months = [
          			"jan",
          			"feb",
          			"mar",
          			"apr",
          			"may",
          			"jun",
          			"jul",
          			"aug",
          			"sep",
          			"oct",
          			"nov",
          			"dec"
          			];
          	return months[this.getMonth()];
          }
          function createLink() {
          	var now = new Date();
          	var year = now.getFullYear();
          	var monthstr = now.getMonthString();
          	var monthnum = (now.getMonth() < 10) ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1);
          	var date = (now.getDate() < 10) ? "0" + now.getDate() : now.getDate();
          
          	document.write("<a href=\"http://www.domain.com/" + year + "/" + monthstr + "/" + monthnum + "" +
          		date + "_print.ppt\">My Link</a>");
          }

          Comment


          • #6
            Well, I've been strugling with this for too long and haven't been able to produce anything close to what I've hoped for. I'd be grateful if anyone had any further ideas for me...

            Comment


            • #7
              So what's wrong with your Javascript code?

              It looks to me as though "some department" will be in charge of creating a powerpoint presentation every day, right?

              I would tell them to make sure they named the file correctly, and I'm pretty sure your Javascript will point to the right file.

              Is there something else? Also, the link in your first post is broken, so I'm not sure what I'm looking at per se. Also, it looks like that is an ASP page, not a PHP. So are you sure that you want help in PHP or ASP?

              I liked Scrowler's idea:
              on your page, maybe

              $file = date("m-d-y").'.php';
              if(file_exists($file)){
              include $file;
              } else {
              echo 'Todays presentation has not been posted yet.';
              }

              then just make a page called (month)-(day)-(year).php every morning.


              hope this helps
              But you say this won't work. I'm assuming because this department doesn't have the knowledge to create a PHP file. Well then instead of including a PHP file, I wonder if you can send a PPT file for download using headers.

              I'm not sure exactly how to do this, but I've seen it on this board somewhere, and I'm sure you could Google it pretty quickly.

              Good luck and let me know if you have any other problems,
              Sadiq.

              Comment


              • #8
                Wow, this has gotten convoluted fast.

                To answer your questions (and I appreciate your taking the time to help out)...

                The reason it needs to be done in PHP is two fold, 1) the site is in PHP (it's a CMS) and 2) the date needs to be taken from the server not the client. They want the latest .ppt presentation, and if they are clear across the world, their client could still output "yesterday".

                The .ppt presentation is already being published everyday on another site and I've been asked to link to it (directly, not to the original page with links).

                The file is being named correctly, no problems there.

                The link I provided is broken, as I am working on an intranet, not an internet site.

                It points to an ASP page, as that is what the site that hosts the .ppt presentation is done with.

                I've actually found a partial solution....

                Code:
                <?php 
                $day = date("md"); 
                $year = date("Y"); 
                echo "<a href=\"http://www.mydomain.com/rep/repository/web/presentations/{$year}/mar_lowband/{$day}_print/ppt.asp?pic=1\">[url]http://www.mydomain.com/rep/repository/web/presentations/[/url]{$year}/mar_lowband/{$day}_print/ppt.asp?pic=1</a>"; 
                ?>
                Problem now is that I need to find a way to add it into this...

                Code:
                $output->Text('<td width=250"><P ALIGN="center"><IMG NAME="button" SRC="image/image.gif"></A><BR><BR><A HREF="__________________">Link name</A></P>');
                $output->Text('</td>');
                Where the underline is where the dynamically created link will reside.

                This is a CMS page that I was given, not something I created myself. The $output->Text is making whatever that follows it be read as straight HTML code, and placing any PHP in it will not result in the PHP being parsed. The page is very large, and rewriting it would take forever.

                So as you can see, I am in a bit of a pickle. I honestly don't expect a solution to this that doesn't have me rewritting the whole thing, but I figured I'd try.

                Comment


                • #9
                  I don't know if this will do it, since I'm sure I don't follow you still, but:

                  PHP Code:
                  $day date("md"); 
                  $year date("Y"); 
                  $link "\"http://www.mydomain.com/rep/repository/web/presentations/{$year}/mar_lowband/{$day}_print/ppt.asp?pic=1\"";

                  $output->Text('<td width=250"><P ALIGN="center"><IMG NAME="button" SRC="image/image.gif"></A><BR><BR><A HREF="$link">Link name</A></P>');
                  $output->Text('</td>'); 
                  Is the CMS page in PHP? If the above doesn't work and actually include the $link in the url, then perhaps that's because the whole thing is in single quotes.

                  In that case, try this:
                  PHP Code:
                  $output->Text("<td width=\"250\"><P ALIGN=\"center\"><IMG NAME=\"button\" SRC=\"image/image.gif\"></A><BR><BR><A HREF=\"$link\">Link name</A></P>"); 
                  I may have missed a \" someplace, which just esapces the " so that it doesn't prematurely close the string. If it's still not working, let me know and we'll try something else.

                  Good luck,
                  Sadiq.

                  Comment


                  • #10
                    The first example you provide actually placed the $link into the URL, but only as http://www.domain.com/$link and didn't seem to catch any data from the $link variable...

                    Comment


                    • #11
                      And the second example.....?

                      Comment


                      • #12
                        The second example produced T_STRING errors on the page...

                        Comment


                        • #13
                          PHP Code:
                          $link "http://www.mydomain.com/rep/repository/web/presentations/{$year}/mar_lowband/{$day}_print/ppt.asp?pic=1";
                          $output->Text('<td width=250"><P ALIGN="center"><IMG NAME="button" SRC="image/image.gif"></A><BR><BR><A HREF="' .$link'">Link name</A></P>'); 

                          Comment


                          • #14
                            That bit of code produces a

                            Parse error: parse error, unexpected T_LNUMBER in D:\inetpub\etc... on line 392
                            Oddly, that line is my closing body tag.

                            Comment


                            • #15
                              My mistake. I forgot to remove a commented piece of code out.

                              This works perfectly. Thank you very much everyone for your assistance. It is very much appreciated.

                              Comment

                              Working...
                              X