Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: appending to html at beginning

by Limbomusic (Acolyte)
on Feb 03, 2017 at 08:58 UTC ( [id://1180939]=note: print w/replies, xml ) Need Help??


in reply to Re: appending to html at beginning
in thread appending to html at beginning

Thanx for lightning fast replies :-) Sadly I am not "mentally equipped" yet - to fully understand how to implement your suggestions, and yes, old code - If I just put
use warnings;
use strict;
I get 500 internal server error - because I guess the code isnt totally "right" ?
I do have tho - a working guestbook (which I found at Matt Wrights website) - and there the entries gets sorted last first - he has some code:
# Open Link File to Output open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!\n +"; for ($i=0;$i<=$SIZE;$i++) { $_=$LINES[$i]; if (/<!--begin-->/) { if ($entry_order eq '1') { print GUEST "<!--begin-->\n"; } if ($line_breaks == 1) { $FORM{'comments'} =~ s/\cM\n/<br>\n/g; } print GUEST "<b>$FORM{'comments'}</b><br>\n";
which I guess has something to do with it - but dont know how to implement it.
I,ll keep investigating and gonna fiddle with your suggestions, but for now, I think I,m just gonna find some html which sends the user to the bottom of the page.
Thank you SO much for your input guys.
Kind regards
Kjartan

P.S - "Madlibs" I guess is the english word - in norwegian - we call it an "adjective story".

Replies are listed 'Best First'.
Re^3: appending to html at beginning
by hippo (Bishop) on Feb 03, 2017 at 09:18 UTC
    I do have tho - a working guestbook (which I found at Matt Wrights website)

    Do be very, very careful with that. There has been plenty of discussion about that collection of scripts over the years and almost all of the recent comments have been uncomplimentary. The scripts are very old and at least some are very insecure. See the summary at the NMS project for some background and how to obtain better versions of those scripts.

    The monks here can help you with your perl questions but if you are going to try to patch some of Matt's old code often the better strategy would be to start again from scratch with the benefit of a modern approach and security as a primary principle.

    Addendum: For the benefit of non-English speakers, there is a word in English which means "appending to the beginning" and it is prepending. Appending is reserved for adding to the end only.

Re^3: appending to html at beginning
by haukex (Archbishop) on Feb 03, 2017 at 09:20 UTC

    Hi Limbomusic,

    I get 500 internal server error - because I guess the code isnt totally "right" ?

    Yes, as described in Use strict and warnings, one of the first things that will happen is that you get errors because you need to declare your variables at or before their first use, for example my $navn = $FORM{navn};. The best way to debug this is by running the script from the command line and looking at the errors you get there. If you're just looking for compilation errors like undeclared variables, you can also run perl -c filename.pl.

    Once you've got the script working locally, if you have trouble on the server, see CGI Help Guide and Troubleshooting Perl CGI scripts.

    a working guestbook

    Please be very careful with code you find like this - what you've shown has a security hole! The problem is print GUEST "<b>$FORM{'comments'}</b><br>\n"; - this allows the visitor to insert any arbitrary HTML code into the page, including JavaScript, which has the potential to seriously mess with the user. This is known as a Cross-site scripting (XSS) attack, for a tutorial see for example this.

    Sorry, but based on the code I have to recommend removing that script from your site, or at least temporarily disabling it. Note: As I was writing this, hippo posted a reply pointing you to a better alternative.

    Hope this helps,
    -- Hauke D

Re^3: appending to html at beginning
by Discipulus (Canon) on Feb 03, 2017 at 09:27 UTC
    I get 500 internal server error - because I guess the code isnt totally "right" ?

    yes you cannot put use strict; use warnings; bare statements without modifying your code. You need to declare all variables you use using my like in my $var = "foo";

    Blindly develop on webserver is, in my experience, a frustrting operation: everything you get wrong you got a 500 error.

    if you want to learn about Modern Perl Web you can start with perldancer.org and it's module Dancer2 it is pretty easy to use.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Hi Discipulus,

      Blindly develop on webserver is, in my experience, a frustrting operation: everything you get wrong you got a 500 error.

      use CGI::Carp qw/fatalsToBrowser/; can help with that. Although I would only recommend it in a development, not production, environment, since it can potentially reveal details about the script or server to an attacker.

      Regards,
      -- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1180939]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found