[EdLUG] Help 10

Matthew Rankine matthew at mrankine.com
Fri May 15 09:33:11 UTC 2020


Hi Andrew, there are some syntax errors on that page. They mean that your
list of books is not being displayed, and actually the PHP code that
contains your password is still being served to clients as plain text (you
can see this by going to View Source in your browser).

The first problem is that the PHP block containing the password starts with
a "<script>" tag. Delete "<script>" and replace with "<?php". This will
match the closing "?>" tag and mean that the server interprets the code in
between as PHP and executes it.

Once that's sorted, there are syntax errors within the PHP block, including:
1. function dirmusic lacks a closing brace }
2. the if $_POST($pwd) line should use == not =
3. the else statement uses ( when it should use {
4. the else statement includes an alert() but this is not PHP at all, it's
JavaScript. You can get PHP to output JavaScript code, but for now it is
easiest to replace the alert("text") with echo "text";.
5. there may be other issues - if you have error reporting enabled in
php.ini as per yesterday's emails, PHP will report error messages which
should help you fix them

best wishes
Matthew

On Fri, 15 May 2020 at 10:17, Andrew Ramage <andrew.ramage.1963 at gmail.com>
wrote:

> I didn't realise that I could use HTML in a php script.  I hand have now
> copied  andrew.html to index.php but only div1 is displayed.  How do I get
> the whole screen displayed ?
>
> On 15/05/2020 09:28, Matthew Rankine wrote:w
>
> As Jeremy says, I would ignore AJAX for the moment.
>
> Andrew, the page you linked (www.andrewnramage.co.uk/andrew.html)
> contains some PHP scripts, but it is being served as HTML. Instead of the
> server recognising it as a php page and executing the code, it is just
> treating it as plain text and sending it all to the browser.
>
> That has the consequence that we can all see your PHP code, including the
> (secret) password!
>
> As a first step, you could rename the file from andrew.html to andrew.php;
> do the same for any other pages containing PHP code; and update any links
> and form actions.
> realisew
> Best wishes
> Matthew
>
> On Fri, 15 May 2020 at 08:43, Andrew Ramage <andrew.ramage.1963 at gmail.com>
> wrote:
>
>> I am trying to set it up so that when a valid login is received, a list
>> of music on the server will be put up on the right half of the screen.
>> See www.andrewnramage.co.uk/andrew.html
>>
>> On 14/05/2020 23:58, Jeremy Nicoll wrote:
>> > On Thu, 14 May 2020, at 21:35, Swithun Crowe wrote:
>> >> Hello
>> >>
>> >> AR> When I use an INPUT form to pass variables to a PHP file, echo
>> prints
>> >> AR> results on a new screen.  How do I get the results printed on the
>> >> AR> calling page ?
>> >>
>> >> For this you'll need Javascript. jQuery is quite a user friendly
>> >> framework.
>> >>
>> >> To have the form submit data to the server without refreshing the whole
>> >> page, you need to use AJAX, which you can also do with jQuery.
>> >
>> > I think AJAX would be .... ambitious for the OP.   I don't think he
>> > understands what's going on, now.
>> >
>> > The HTML form (executing in the user's browser) is NOT "passing
>> variables
>> > to a PHP file".  The user's browser is making a separate (in essence)
>> page
>> > fetch, from the webserver, asking it to execute the php script on the
>> server
>> > and is as part of that, including the 'passed' variables' values on the
>> fetch
>> > request.   The response from that is another web page generated by the
>> > php script (on the server) which is sent back to the user for their
>> browser
>> > to display.
>> >
>> > /Maybe/ if the generated html page returned by that php script also
>> > contained a copy of the form, with the results displayed somewhere on
>> > the page one could /appear/ to have displayed results on the original
>> > page that contained the form... but it is not the same page.
>> >
>> > The php code on the server is not being called (in the sense that most
>> > programming languages can call an external function) by any of the code
>> > (not that there is any) in the original html page.  It's the browser
>> that makes
>> > the second fetch request, when processing the submit action on the form.
>> >
>> > As Swithin says, if the OP want's (his) program logic to affect the way
>> any of
>> > his html pages process things, within the user's browser, that needs to
>> be
>> > done in JavaScript (or any other supported script language).  That code
>> > though can't 'call' php stuff on the server either.
>> >
>> >
>> > It might help if the OP would describe what he thinks he wants the user
>> > to do and see on these pages.
>> >
>> >
>>
>> --
>> EdLUG mailing list
>> EdLUG at lists.edlug.org.uk
>> https://lists.edlug.org.uk/mailman/listinfo/edlug
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.edlug.org.uk/pipermail/edlug/attachments/20200515/314753d4/attachment-0001.html>


More information about the EdLUG mailing list