Help with deciphering a PHP script

I’m interested in modifying a pre-written PHP web script. I’m no expert at PHP code, but have some level of knowledge of it. I’m trying to figure out how to modify the social media link boxes on it’s login page. Which is this line of code:

<?php echo pvs_get_social_networks();?>

I know this because when I comment out this line, the social media link boxes disappear.
I believe the pvs is the initials of the script name.
So, I’m trying to learn more about this script, before I contact the developer directly.

Based on the file’s code (named members/login_content.php) provided below, could you provide any suggestions/guess on how I might determine where I could modify the social media link boxes? Any enlightenment will be appreciated.

<?php
if ( ! defined( "site_root" ) ) {
	exit();
}
?>
<div id="login_content">
<table border="0" cellpadding="0" cellspacing="0" width="90%">
<tr valign="top">
<td style="width:50%">
	<div class='login_header'><h2><?php echo pvs_word_lang( "login" )?></h2></div>
	<form method='post' action='<?php echo site_root?>/members/check.php'>

	<div class="form_field">
	<span><?php echo pvs_word_lang( "user" )?>:</span>
	<input class='ibox form-control' type='text' name='l' style='width:100px;'>
	</div>
	
	<div class="form_field">
	<span><?php echo pvs_word_lang( "password" )?>:</span>
	<input class='ibox form-control' type='password' name='p' style='width:100px;'>
	</div>
	
	<div class="form_field">
	<input class='isubmit' type='submit' value="<?php echo pvs_word_lang( "login" )?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='<?php echo site_root?>/members/forgot.php'><?php echo pvs_word_lang( "forgot password" )?>?</a>
	</div>
	
	</form>

	
	
	<div class='login_header' style="margin-top:30px"><h2><?php echo pvs_word_lang( "sign up" )?></h2></div>
	<p>
<?php
$sql = "select * from " . PVS_DB_PREFIX . "pages where link='login'";
$rs->open( $sql );
if ( ! $rs->eof ) {
	echo ( pvs_translate_text( $rs->row["content"] ) );
}
?>
</p>
	
	<div class="form_field">
	<input class='isubmit' type='button' onClick="location.href='<?php echo site_root?>/members/signup.php'" value="<?php echo pvs_word_lang( "sign up" )?>">
	</div>
	
	
	
</td>
<td style="padding-left:30px;width:50%">
	<div class='login_header'><h2><?php echo pvs_word_lang( "login without signup" )?>:</h2></div>
	<?php echo pvs_get_social_networks();?>
	
	
	<?php
if ( $pvs_global_settings["site_guest"] and ! $pvs_global_settings["credits"] and
	$site == "checkout" ) {
?>
	
		<script language="javascript">
 		function check_guest_email()
 		{
 			email=document.getElementById('guest_email').value;
			if(email.match (/^[0-9a-zA-Z\-_\.]+@[0-9a-zA-Z\-_\.]+\.[a-zA-Z]+$/))
			{
	return true;
			}
			else
			{
 	document.getElementById('guest_email').className = 'ibox_error';
 	document.getElementById('error_email').innerHTML = '<?php echo pvs_word_lang( "incorrect" )?>';
 	return false;
 			}
 		}
 		
 		function pvs_show_captcha()
 		{
 			$("#captcha_box").slideDown("slow");
 		}
		</script>
		

		
		
		<div class='login_header' style="margin-top:30px"><h2><?php echo pvs_word_lang( "login as guest" )?></h2></div>
		
		<?php
	if ( isset( $_GET["error"] ) ) {
		if ( $_GET["error"] == "email" ) {
			echo ( "<p><b>Error. The email is already in use</b></p>" );
		}
		if ( $_GET["error"] == "captcha" ) {
			echo ( "<p><b>Error. Incorrect Captcha.</b></p>" );
		}
	}
?>
	
		<form method='post' action='<?php echo site_root?>/members/check_guest.php' onSubmit="return check_guest_email();">
	
		<div class="form_field">
		<span><?php echo pvs_word_lang( "e-mail" )?>:</span>
		<input class='ibox form-control' type='text' name='guest_email'  id='guest_email' style='width:150px;' onClick="pvs_show_captcha()" value="<?php
	if ( isset( $_SESSION["guest_email"] ) ) {
		echo ( pvs_result( $_SESSION["guest_email"] ) );
	}
?>"><div id="error_email" class="error"></div>
		</div>
		<div class="form_field" <?php
	if ( ! isset( $_GET["error"] ) ) {
?>style="display:none"<?php
	}
?> id="captcha_box">
			<?php
	//Show captcha
	require_once ( '../admin/plugins/recaptcha/recaptchalib.php' );
	echo ( pvs_show_captcha() );?>
		</div>
	
		<div class="form_field">
		<input class='isubmit' type='submit' value='<?php echo pvs_word_lang( "OK" )?>'>
		</div>
	
		</form>
	<?php
}
?>
	
	
</td>
</tr>
</table>
</div>

In the function?

Yes, that is calling a function.
Find where the function of that name is defined. It will likeley either be in the script or in an include included in the script.

1 Like

Much thanks

At the top of the file, you see this code. This prevents the file from executing in the first place when a web browser attempts to load it directly because “site_root” is not defined. That means that the function will likely be defined elsewhere and this file is included/required from another file. From a command line, you can ‘cd’ to the directory where the website files live and run a command like this on Windows:

findstr /sic:“pvs_get_social_networks” *.php

Or a similar command at a Linux/Mac command line (terminal or SSH session):

grep -nir --include=“*.php” “pvs_get_social_networks” .

That will locate all files that either define or call the function named pvs_get_social_networks() and show each line that matches. The function itself should stand out pretty quickly.

Thanks for that explanation & instruction. Very helpful/appreciated.
When you say “This prevents the file from executing in the first place when a web browser attempts to load it directly because “site_root” is not defined”. That’s a good thing ?

I have worked with older PHP, that’s why this is a learning curve for me.

I’d like to ask for additional guidance, please.

The text, for example, on the displayed log-in page shows:
“You have not signed up for your free account. The registration process is quick and easy. Once you have an account, you will be able to make a purchase from our website.”

Yet, the login-content.php shows:

<?php
$sql = "select * from " . PVS_DB_PREFIX . "pages where link='login'";
$rs->open( $sql );
if ( ! $rs->eof ) {
	echo ( pvs_translate_text( $rs->row["content"] ) );
}
?>

Can you shed some light on where I would go to modify the displayed page text?

Much thanks again

My guess is that the text is recovered from the table that is called

PVS_DB_PREFIX . pages

where PVS_DB_PREFIX must be defined somewhere. It seems that it displays the content column from that table, if the code snippet is doing that.

Thanks for your accurate ‘guess’. I went to the db and table ‘pages’ and at the bottom I see the text in question “You have not signed up for your free account …”
(see attached image).
So, based on what I see it shows under ‘url’ column: /pages/login.html
I’ve manually looked around the main script folder and don’t see a ‘pages’ folder.
Is their a more efficient way to search a script’s folders/files?
Or does this text only get modified in the db table?
Any additional ideas/guidance will be much appreciated.

There may be some rewrite rules going on in your .htaccess file that mean the files or pages are stored elsewhere. Equally, that column might not be in use. The query to retrieve the text only passes in the link column value and retrieves the text from content, then sends that to the function.

Easy way to find out - change it in the db table, and see if your screen output changes.

Note that the query has the value of PVS_DB_PREFIX stuck on the beginning of it, so you need to find out what’s in that in case it points to a different table, something that just ends in pages.

Thanks for your replies.

I have received a reply from the developer that said:

“The most of seo-friendly URLs are virtual. The html files don’t exist really. They are created by Apache mod_rewrite (there is /htaccess file with mod_rewite instructions)”

The htaccess file looks like this, here’s a sample:

RewriteEngine on
RewriteBase /

RewriteRule ^category\/([\w-]+).html$ index.php?category=$1 [L]
RewriteRule ^category\/([a-z]+)\/([\w-]+).html$ index.php?category=$2&vd=$1 [L]
RewriteRule ^static([0-9]*)\/preview([0-9]*)\/[\w-]+-([0-9]+).(jpg|jpeg|flv|swf|wmv|mp4|mp3|mov)$ content$1/$3/thumb$2.$4 [L]

And here’s an example of what the php looks like this:

<?php
$site = "login";
include ( "../admin/function/db.php" );?>
<?php
if ( isset( $_SESSION["people_id"] ) ) {
	header( "location:" . site_root . "/" );
}
?>
<?php
include ( "../inc/header.php" );?>

<h1><?php echo pvs_word_lang( "member area" )?></h1>


<?php
if ( isset( $_GET["d"] ) ) {
	if ( $_GET["d"] == 1 ) {
		echo ( "Error. The login is incorrect." );
	}
	if ( $_GET["d"] == 2 ) {
		echo ( "Error. You failed to login several times. The new password was generated and sent to your email." );
	}
	if ( $_GET["d"] == 3 ) {
		echo ( "Error. The IP was blocked" );
	}
}
?>
<?php
include ( "login_content.php" );?>
<?php
include ( "../inc/footer.php" );?>

(the text files are in the admin panel)
This is pretty new to me. How tough would it be to make design changes of this script?
I’m used to modifying code in a file page and css changes.

I look forward to your comments/guidance.

There’s plenty of documentation around on how .htaccess rewrites work, and I’ve never tried it myself. My guess is:

  1. When someone navigates to a page called /category/something.html, that gets sent to index.php with a parameter called category which is set to whatever the “something” was.

  2. When someone navigates to a page called /category/moretext/something.html, that gets sent to index.php with a parameter called category set to whatever “something” was, and a second parameter called vd with a value of whatever the moretext was.

  3. No idea

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.