Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Noobie Question] Finding PHP code

Featured Replies

I have made very basic html-only websites in the past but now need to edit a php-based website.

I am trying to a a CAPTCHA to my grandparents' website because of bot issues they have been having.

I will be using a tutorial.

However, I cannot find the code for their contact page anywhere on their web server. The page is DOMAIN.CO.UK/index.php?id=6

How do I get to the code of the web form at /index.php?id=6?

  • Author

look for any refrences of $_GET['id']

Nothing still :/

 

I did a search in the document for "GET[" with no results.

 

Can I PM you the index.php file (Its only 5KB) for you to do a very quick look over if you wouldn't mind?

You first need to look at the source code of the page that has the form.

 

Look at the source code of the form, can you see action="..." with a filename inside the "..." which will be the PHP process file where you need to add the captcha code? I assume that your parents have given you ftp access to this file and download it from the server.

  • Author

 

Look at the source code of the form, can you see action="..." with a filename inside the "..." which will be the PHP process file where you need to add the captcha code? I assume that your parents have given you ftp access to this file and download it from theserver.

 

It is the source code for the form that I cannot find. Yes, I have full FTP access.

Edited by PHPNoobie

You can post the source code here. Just take out any 'http://' and you should be good to go.

 

Use the [code ] tags :)

  • Author

This is index.php in the directory for the website.

<?php
/*
*************************************************************************
    MODx Content Management System and PHP Application Framework
    Managed and maintained by Raymond Irving, Ryan Thrash and the
    MODx community
*************************************************************************
    MODx is an opensource PHP/MySQL content management system and content
    management framework that is flexible, adaptable, supports XHTML/CSS
    layouts, and works with most web browsers, including Safari.

    MODx is distributed under the GNU General Public License    
*************************************************************************

    MODx CMS and Application Framework ("MODx")
    Copyright 2005 and forever thereafter by Raymond Irving & Ryan Thrash.
    All rights reserved.

    This file and all related or dependant files distributed with this filie
    are considered as a whole to make up MODx.

    MODx is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    MODx is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MODx (located in "/assets/docs/"); if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

    For more information on MODx please visit http://modxcms.com/
    
**************************************************************************
    Originally based on Etomite by Alex Butter
**************************************************************************
*/    

/**
 * Initialize Document Parsing
 * -----------------------------
 */
 
// is this file included?
if(count(get_included_files())>1) $noparser = true;

// get start time
$mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $tstart = $mtime;

// harden it
require_once(dirname(__FILE__).'/manager/includes/protect.inc.php');

// set some settings, and address some IE issues
@ini_set('url_rewriter.tags', '');
@ini_set('session.use_trans_sid', 0);
@ini_set('session.use_only_cookies',1);
session_cache_limiter('');
header('P3P: CP="NOI NID ADMa OUR IND UNI COM NAV"'); // header for weird cookie stuff. Blame IE.
header('Cache-Control: private, must-revalidate');
ob_start();
error_reporting(E_ALL & ~E_NOTICE);

/**
 *    Filename: index.php
 *    Function: This file loads and executes the parser. *
 */

define("IN_ETOMITE_PARSER", "true"); // provides compatibility with etomite 0.6 and maybe later versions
define("IN_PARSER_MODE", "true");
define("IN_MANAGER_MODE", "false");

// initialize the variables prior to grabbing the config file
$database_type = '';
$database_server = '';
$database_user = '';
$database_password = '';
$dbase = '';
$table_prefix = '';
$base_url = '';
$base_path = '';

// get the required includes
if($database_user=="") {
    $rt = @include_once(dirname(__FILE__).'/manager/includes/config.inc.php');
    // Be sure config.inc.php is there and that it contains some important values
    if(!$rt || !$database_type || !$database_server || !$database_user || !$dbase) {
    echo "
<style type=\"text/css\">
*{margin:0;padding:0}
body{margin:50px;background:#eee;}
.install{padding:10px;border:5px solid #f22;background:#f99;margin:0 auto;font:120%/1em serif;text-align:center;}
p{ margin:20px 0; }
a{font-size:200%;color:#f22;text-decoration:underline;margin-top: 30px;padding: 5px;}
</style>
<div class=\"install\">
<p>MODx is not currently installed or the configuration file cannot be found.</p>
<p>Do you want to <a href=\"install/index.php\">install now</a>?</p>
</div>";
        exit;
    }
}

// start session
startCMSSession();

// initiate a new document parser
include_once(MODX_MANAGER_PATH.'/includes/document.parser.class.inc.php');
$modx = new DocumentParser;
$etomite = &$modx; // for backward compatibility

// set some parser options
$modx->minParserPasses = 1; // min number of parser recursive loops or passes
$modx->maxParserPasses = 10; // max number of parser recursive loops or passes
$modx->dumpSQL = false;
$modx->dumpSnippets = false; // feed the parser the execution start time
$modx->tstart = $tstart;

// Debugging mode:
$modx->stopOnNotice = false;

// Don't show PHP errors to the public
if(!isset($_SESSION['mgrValidated']) || !$_SESSION['mgrValidated']) @ini_set("display_errors","0");

// execute the parser if index.php was not included
if(!$noparser) $modx->executeParser();
exit;
?>

Edited by PHPNoobie

They're using the ModX content management system (CMS). You should be able to enable CAPTCHA via the admin area.

 

Edit: To be clear, you shouldn't be doing this manually. The site is built on a CMS. You should be building a plugin, or using an existing plugin.

Edited by andy9l

  • Author

They're using the ModX content management system (CMS). You should be able to enable CAPTCHA via the admin area.

 

Edit: To be clear, you shouldn't be doing this manually. The site is built on a CMS. You should be building a plugin, or using an existing plugin.

I see no options for adding a CAPTCHA using the admin pages of the manager.

 

There is however an editable textbox for the page that I want. Currently it contains standard page text above and then this (Email address mutated):

 

 

[[Contac tForm? &sendTo=`[(emailsender)]`]] [!eForm?
&formid=`ContactForm` &subject=`[+subject+]`
&to=`EMAILGOESHERE@EMAIL.COM` &ccsender=`1` &tpl=`ContactForm`
&report=`ContactFormReport` &gotoid=`46` !]
  • Author

see here

c

heck the modx form plugins here

 

formit is most popular and it has spam protection

Thank you for that.

 

I will likely install that.

The instructions for installation say to do so via Package Management, I have logged into DOMAIN.co.uk/manager and looked through it but cannot see any reference to anything called "package manager" (I assume I am using an old version of ModX). From the version I am using, how can I install these plugins?

  • Author

Just posting infromation as I find it.

 

I have been looking through the ModX pages and found this HTML code fro the web form:

 

 

<p class="error">[+validationmessage+]</p>

<form method="post" action="[~[*id*]~]" id="EmailForm" name="EmailForm">

        <h3> Contact Form</h3>

        <input name="formid" type="hidden" value="ContactForm" />

        <label for="cfName">Your name:<br />
        <input name="name" id="cfName" class="text" type="text" eform="Your Name::1:" /> </label><br /><br />

        <label for="cfEmail">Your Email Address:<br />
        <input name="email" id="cfEmail" class="text" type="text" eform="Email Address:email:1" /> </label><br /><br />

        <label for="cfRegarding">Regarding:</label><br />
        <select name="subject" id="cfRegarding" eform="Form Subject::1">
            <option value="General Enquiries">General Enquiries</option>
            <option value="Booking Enquiries">Booking Enquiries</option>
            
        </select><br /><br />

        <label for="cfMessage">Message: <br />
        <textarea name="message" id="cfMessage" rows="4" cols="50" eform="Message:textarea:1"></textarea>
        </label><br />

        <label> </label><input type="submit" name="contact" id="cfContact" class="button" value="Send This Message" />



</form>

 

Can something be implimented here, even if extremely simple, just to combat the most basic of bots?

  • Author

I am using ModX 0.9.6, I believe that the package management was introduced with ModX 2.0. So I can;t install these plugins, right?

I am using ModX 0.9.6, I believe that the package management was introduced with ModX 2.0. So I can;t install these plugins, right?

ya if thts wht u see. u need to update ur modx ver check this thread

 

and u shld use the modx community for solving issues ;)

Edited by sash_oo7

  • Author

ya if thts wht u see. u need to update ur modx ver check this thread

 

and u shld use the modx community for solving issues ;)

So I would need to update from 0.9.6 to 2.0.0 in order to install a CAPTCHA add-on?

 

As there is no direct update fromt hese two versions available and it must be a manual update, I really do not think that I have the knowledge to do this. I would not trust myself considering it it not my website. It this were my own site I would have a go but I am too worried considering if I mess it up, it seriously affects my grandparent's income.

 

 

It there any alternative?

 

I do not really care if the turing check is incredibly basic and would only repel 1% of bots - to be honest, as logn as my grandparents can see I've tried, they would be happy.

 

 

 

Is there a way of adding something along the lines of a label and textbox saying "Enter the number four in numbers below" and the form would not be submitted unless "4" was entered into the textbox?

I would not realy need the number to change each time, even if it were 4 for everyone.

 

Can this be done even if a rather crude implementation?

  • Author

Alternatively. This seems promising (Basic I know, but far simpler):

www.sitepoint.com/easy-spam-prevention-using-hidden-form-fields/

 

 

if I were to input this code:

 

<input type="text" name="foo" style="display: none;">

 

How do I then implement the following procedure (pseudo code)?

 

when submitButton is pressed{
          if foo is empty{          // foo is the text field name as above
                    submit form
          }
          else{
                    do not submit form
          }
}

 

Sorry that this has turned into more HTML than PHP.

(I can insert HTML code into the page using that ModX page I found, right?)

 

 

 

 

EDIT: (Just editting as I think of things)

 

I am guessing that the form is handled by an external PHP file/procedure. Therefore would my possible solution be possible by the check for the value of "foo" beign done using HTML only, if the check is failed, the from is just not submitted to the PHP procedure at all? If it passes, the form can be submitted as usual?

Edited by PHPNoobie

You cannot do logic like you've described using HTML. You'd need to use Javascript, but then Javascript is pointless as bots tend to ignore it.

 

You need to do your validation using PHP – server-side.

There is an opinion that Captchas are not worth using now, they can be difficult for users to read and bots can recognise some of them.

 

I use a hidden input box that PHP checks is empty after submission. Humans don't see the hidden box so leave it empty but bots will fill the input automatically and get the form rejected.

Typical PHP code;

// If a bot is attempting to send spam it will complete this input while viewers don't see the visibility: hidden box 
elseif ($_POST['catchbot'] !="") {//Boot it out of the server 
die();}
but elseif may need to be if or else depending on your PHP coding. !="" means value NOT equal to nothing.

Add html for an input in the normal way with name="catchbot"

<input name="catchbot" class="botcatch" type="text" value="">
and a style
input.botcatch { visibility: hidden; height: 0; line-height: 0; font-size: 0; margin:0; padding:0; border: none; }

Edited by Wickham

  • Author

 

There is an opinion that Captchas are not worth using now, they can be difficult for users to read and bots can recognise some of them.

 

I use a hidden input box that PHP checks is empty after submission. Humans don't see the hidden box so leave it empty but bots will fill the input automatically and get the form rejected.

Typical PHP code;

// If a bot is attempting to send spam it will complete this input while viewers don't see the visibility: hidden box 
elseif ($_POST['catchbot'] !="") {//Boot it out of the server 
die();}
but elseif may need to be if or else depending on your PHP coding. !="" means value NOT equal to nothing.

Add html for an input in the normal way with name="catchbot"

<input name="catchbot" class="botcatch" type="text" value="">
and a style
input.botcatch { visibility: hidden; height: 0; line-height: 0; font-size: 0; margin:0; padding:0; border: none; }

This seems similar to that link I posted last night. I really like this solution. I have not looked into it much btu ti seems fairly simple to implement, right? And it also doesn't alter the webpage either so it means that my grandparents will not object at all to it (They wouldn't really care even if I did change the webpage a little to be honest).

Yes, it is the same method; I didn't read your post carefully.

 

The PHP will vary as it has to be tailored to suit the php code used elsewhere.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.