Jump to content

A Couple Questions .. One On Require.. One On Sessions


spdwrench

Recommended Posts

First Question

 

I Run a free dating site run on php script.

 

the index.php page is handling most of the actions.. there is a require "loadconfiguration.php";

 

is this loading the configuration everytime the index.php is refreshed? if so I heard about require once

 

will this help the load on my server by only requiring the configuration load once per session?

 

please advise...

 

also everyonce in a while I get members telling me they try to email people and the wrong name pops up

 

it seems if they restore the internet explorer defaults and erase cookies this fixes that...

 

is there a way to make sure this does not happen? I have a feeling it is with cookies but not sure... it seems to happen to internet explorer users once in a blue moon. where the recieving member is not the one they choose. but if the same user uses firefox it works fine for them...

 

is there a simple comand to illiminate this type of problem I think it has something stored from previous session I dunno... I really need to read up on sessions and cookies because I am not that knowledgable in these areas...

 

Any help with this is greatly appreciated

 

Paul

 

abmatch

Link to comment
Share on other sites

is this loading the configuration everytime the index.php is refreshed?

 

yes.

 

will this help the load on my server by only requiring the configuration load once per session?

 

no. require_once ensures that 1. the files is loaded and 2. the file is loaded only once on that page.

 

also everyonce in a while I get members telling me they try to email people and the wrong name pops up

 

need more details on this. please describe the process and/or post code. it sounds like a page caching problem at first glance.

Link to comment
Share on other sites

the require once thing

 

so it only makes sure it is required once per that page?

 

so say I wanted it to load configuration only once

 

then should I set a variable in the loadconfiguration.php like $loaded=1;

 

then in the front of index.php put something like this

 

if ($loaded!=1){require "loadconfiguration.php"};

 

Would that be a way to keep it from reloading a bunch of times per member visit?

 

 

the second question.. the page cache thing... this only happens rarely but I wish I had more info on it

it gets stuck emailing the wrong person and no matter who they try to email it shows the same other person.

 

if it is what you think is there a way to make sure this is cleared when members arive to the signin page?

 

I will try to get more info on this if possible

 

thanks for your input

 

Paul

 

Link to comment
Share on other sites

if ($loaded!=1){require "loadconfiguration.php"};

will work better that require_once (as require_once will back track to see if it has loaded, which is slower)

 

as for the problem with the email, can they choose the email option from many different places, if so try to find the place it cause the problem, you really need to be able to recreate the problem over and over to find the solution either that or blind shooting.. try looking at the forms and JS as most of the problems with IE vs FF are in those areas

Link to comment
Share on other sites

Here Is The Send Message Code....

 

<?
    if($action == "send")
{   
        $fBlocked = f(q("SELECT id FROM dt_blocked WHERE member_id = '$rid' and blocked_id = '$fMember[id]'"));
        if ($fBlocked[id] != "")
        {
             $errors_num++;
             $errors_string .= $errors_num . "You have been blocked by this user!" . "<br>\n";
        }
        if ($rid =="")
        {
             $errors_num++;
             $errors_string .= $errors_num . "Please enter a recepient." . "<br>\n";
        }
        if ($subject =="")
        {
             $errors_num++;
             $errors_string .= $errors_num . "Please enter a subject." . "<br>\n";
        }
        if ($message =="")
        {
             $errors_num++;
             $errors_string .= $errors_num . "Please enter a message." . "<br>\n";
        }
        if ($errors_num)
        {
            $r_records = q("SELECT * FROM dt_address_book WHERE member_id='$fMember[id]'");
   
           $send_message_content .= '<select name="rid">';
        	
          	while($f_record = f($r_records))
          	{
           		$f_profile = f(q("SELECT name, member_id FROM dt_profile WHERE id='$f_record[contact_profile_id]'"));
           		$f_member = f(q("SELECT login FROM dt_members WHERE id='$f_profile[member_id]'"));
           		$profile_name = $f_member[ login ];
                
           		if($f_profile[ member_id ] != $fMember[id])
           			$send_message_content .= '<option value="'.$f_profile[ member_id ].'">'.$profile_name.'</option>';
			echo "33";
           		$cnt = 1;
          	}
          	if(!$cnt)
          	{
          		$send_message_content .= '<option>'."No Contact Available".'</option>';
          	}
          	
          	$send_message_content .=  '</select>';
          	$error_text = $errors_string;
          	$form_errors = parseVariables("templates/forms/form_errors.html",0);
          	$form_errors = '<tr>
    									<td bgcolor="#F0F0F0">
    										<hr noshade size=1>
    										'.$form_errors.'
    										<hr noshade size=1>
    									</td>
    								</tr>';
           parseVariables("templates/send_message.html");
        }
        else
        {
		$t = time();
		q("INSERT INTO dt_messages (sid, rid, subject, message, timesent, show_in_inbox, show_in_sent) VALUES (".$fMember[id].", $rid, '$subject', '$message', '$t', '1', '1')");

		// Begin New Code 
		$action = "add";
		$owner_member_id = $fMember[id];
		$member_id = $rid;
		$hotlist_type = "messaged";


		include "engine/pages/hot_lists.php";
		// End New Code for webDate 1.3.6

		include "engine/pages/message_sent.php";


		$query = "select * from dt_members where id = '$rid'";
		$user_info = f(q($query));
		$login = $user_info["login"];
		$generated_link = $root_host."index.php?page=sign_in";
		mailSend($user_info["email"], "new_mail.html");
        }
}
else if($action == "new")
{ 
  		$f_balance = f(q("SELECT balance FROM dt_stamps_balance WHERE member_id='$fMember[id]'"));
	$action = "";
	$free_profile = 0;
	$can_contact = 0;
	$valid = 0;

	if($fMember[id] == "") return;

	if(($fMember[ unlimited ] && $fMember[ unlimited_end ] > time()) || $free_initiate) $free_profile = 1;
	else if($f_balance[ balance ] >= 1) $can_contact = 1;
	if(!$free_profile && !$can_contact)
	{
        	$include_link = "engine/pages/cannot_contact.php";
	}

	$max_messages = 0;
	if($free_profile)
	{
		if($fMember[system_status] || $fMember[unlimited])
			$max_messages = $paying_max_messages;
		else
			$max_messages = $nonpaying_max_messages;

		$time_from = time() - (24*60*60);
		$time_to = time();

		$count = f(q("SELECT COUNT(*) AS count FROM dt_messages WHERE sid='$fMember[id]' AND timesent>='$time_from' AND timesent<='$time_to'"));
		$count = $count[count];

		if($count < $max_messages)
		{
    		$valid = 1;
    		include "engine/pages/send_message.php";
			return;
		}
		else
		{
			parseVariables("templates/cannot_contact.html");
			return;
		}
	}

	if($can_contact)
	{
		if($fMember[system_status] || $fMember[unlimited])
			$max_messages = $paying_max_messages;
		else
			$max_messages = $nonpaying_max_messages;

		$time_from = time() - (24*60*60);
		$time_to = time();

		$count = f(q("SELECT COUNT(*) AS count FROM dt_messages WHERE sid='$fMember[id]' AND timesent>='$time_from' AND timesent<='$time_to'"));
		$count = $count[count];

		if($count < $max_messages)
		{
			q("UPDATE dt_stamps_balance SET balance=balance-1 WHERE member_id='$fMember[id]'");

			$valid = 1;

			//include "engine/pages/send_message.php";
			return;
		}
		else
		{
			parseVariables("templates/cannot_contact.html");
			return;
		}
	}
}
    else
    {
        if((($reply == "") && (!$valid)) || (!$free_reply && $fMember[unlimited] != 1))
        {
        		$include_link = "engine/pages/cannot_contact.php";
            return;
        }
        if ($reply != "")
        {
            $r_records = q("SELECT * FROM dt_messages WHERE id=$reply");
        }
        elseif ($mid != "")
        {
            $f_record = f(q("SELECT * FROM dt_address_book WHERE (member_id='$fMember[id]' AND contact_profile_id = '$mid')"));
        }
        elseif ($pid != "")
        {
            $f_record = f(q("SELECT * FROM dt_address_book WHERE (member_id='$fMember[id]' AND contact_profile_id = '$pid')"));
        }
        else
        {
            $r_records = q("SELECT * FROM dt_address_book WHERE member_id='$fMember[id]'");
        }
	$valid = 1;
    }
    if($valid)
    {
    	include($include_link);

    	$send_message_content = "";
	$cnt = 0;
		if ($errors_num)
		{
			$form_errors = parseVariables("templates/forms/form_errors.html",0);
			$form_errors = '<tr>
    								<td bgcolor="#F0F0F0">
    									<hr noshade size=1>
    									'.$form_errors.'
    									<hr noshade size=1>
    								</td>
    							</tr>';
		}

	$msg_subject = "";
	$msg_body = "";
	if ($reply != "")
	{
		$cnt = 1;
   			$f_record = f($r_records);
		if(substr($f_record["subject"], 0, 3) != "Re: ")
		{
			$msg_subject = "Re: ".$f_record["subject"];
		}
		else
		{
			$msg_subject = $f_record["subject"];
		}
		$msg_body = "\n\n\n> ".preg_replace("/\n/", "\n> ", $f_record["message"]);

   			$f_members = f(q("SELECT login FROM dt_members WHERE id='".$f_record["sid"]."'"));
   			$profile_name = $f_members["login"];
   			if ($f_record["rid"] == $fMember[id] || $f_record["sid"] == $fMember[id])
   			{
                $send_message_content .= '<input type="hidden" name="rid" value="'.$f_record["sid"].'">';
                $send_message_content .= $profile_name;
   			}
   			else { $send_message_content .= 'Error';}
	}
	else if ( $pid != "" )
	{
   			$f_profile = f(q("SELECT name, member_id FROM dt_profile WHERE member_id='".$f_record[contact_profile_id]."'"));
   			$f_member = f(q("SELECT login FROM dt_members WHERE id='".$f_profile[member_id]."'"));
   			$profile_name = $f_member[ login ];
   			$cnt = 1;
                    
   			$send_message_content .= '<input type="hidden" name="rid" value="'.$f_profile[member_id].'">';
            $send_message_content .= $profile_name; 
	}
	else if ( $mid != "" )
	{
   			$f_profile = f(q("SELECT name, member_id FROM dt_profile WHERE id='".$f_record["contact_profile_id"]."'"));
   			$f_member = f(q("SELECT login FROM dt_members WHERE id='".$f_profile["member_id"]."'"));
   			$profile_name = $f_member[ login ];
   			$cnt = 1;

         	$send_message_content .= '<input type="hidden" name="rid" value="'.$f_profile[member_id].'">';
            $send_message_content .= $profile_name; 
	}
	else
	{
        	$send_message_content .= '<select name="rid">';
        	
          	while($f_record = f($r_records))
          	{
           		$f_profile = f(q("SELECT name, member_id FROM dt_profile WHERE id='$f_record[contact_profile_id]'"));
           		$f_member = f(q("SELECT login FROM dt_members WHERE id='$f_profile[member_id]'"));
           		$profile_name = $f_member[ login ];
                
           		if($f_profile[ member_id ] != $fMember[id])
           			$send_message_content .= '<option value="'.$f_profile[ member_id ].'">'.$profile_name.'</option>';

           		$cnt = 1;
          	}
          	if(!$cnt)
          	{
          		$send_message_content .= '<option>'."No Contact Available".'</option>';
          	}
          	
          	$send_message_content .=  '</select>';
	}

	$input_disabled = ($cnt) ? ("") : ("disabled");
    	
    	parseVariables("templates/send_message.html");
    }
    else
    {
	include($include_link);
    }


?>

 

Let me know if you need to look at anything else... this is the send message page that is pulling up the wrong receipiant for isolated members on occations...

 

thanks

 

Paul

Link to comment
Share on other sites

Erm.. whats the

fucntion f

and function q

 

ie

$user_info = f(q($query));

 

 

also $fMember[id] should be $fMember['id']

$f_profile[member_id] should be $f_profile['member_id']

etc etc etc

 

if id is an int it shoud not be quoted

WHERE id='$f_profile[member_id]'

 

Link to comment
Share on other sites

Ok thanks for looking it over,, like I said it is isolated incidents so I think it has something to do with people internet settings in the browser possibly.. because I have told people to do a restore defaults and it seemed to solve the issue for some.

 

Anyway A new questions about the require thing.

 

I am new to php but have done alot of modifications to my script like image resizing and branding and integrating forums with autologin and stuff.. but honestly I am still such a newbie...

 

Here is my silly question

 

the index.php file

 

require "config.php"

 

in config.php I asing $confload=1;

 

when I put in the index.php

 

if  ($confload!=1){require "config.php";}

 

the problem is $confload is never 1 how can I make this global?

 

thanks I know it's probally simple but I get a little lost.

 

Paul

Link to comment
Share on other sites

that locked up my page and got a white screen... I took it out in put the straight require back in and it loaded...

 

I will play with it tomorow on my day off and get back to you..

 

is there a reason why this method would work better then just asigning a variable? and do you know why my variable was not acting global? can I asign a variable for the life of the session somehow?

 

thanks

 

Paul

Link to comment
Share on other sites

I am still trying to make this happen

 

how do I use classes with oop?

 

could you give me an idea.

 

because I know this require "config.php";

 

is really dragging down the site speed if it only loads on initial page would be alot faster

 

the people who wrote this code actually had it checking my whole userbase everytime a new page was called from the index.php it was check to see who became a year older on every single page load... I took that out and it moves alot faster now if I could get this fixed we will be like lightening...

 

:)

 

Paul

Link to comment
Share on other sites

to speed things up you need to know exactly whats slowing it down..

i assume you know its a file.. the next step is what part..

if its SQL related then maybe some cacheing

 

the fact is i could show you how to check if the file is included but require_once isn't really that slow (it could total up to 2 seconds (total guess) if you had it everywhere over 1000s of files).

 

Link to comment
Share on other sites

currently it is using require

 

require "engine/load_configuration.php";

 

 

<?



$smartway_dir     = "smartway/";
$smartway_lib_dir = $smartway_dir."lib/";
$smartway_srv_dir = $smartway_dir."services/";

//  Loading libraries

require $smartway_lib_dir."system.lib";
require $smartway_lib_dir."mod_xml.lib";
require $smartway_lib_dir."mod_xml_ct.lib";
require $smartway_lib_dir."mail.lib";

//  Loading configuration

require $smartway_srv_dir."BD3LoadConfiguration.service";
require $smartway_srv_dir."BD3LoadDBDevice.service";

// include functions.lib file.
require $smartway_lib_dir."functions.lib";
//require $smartway_lib_dir."lang.lib";

?>

 

this is the code that is in the load_configuration.php file.

 

it seems it is loading all the functions and things it needs to run the script. But why does it need to load this everytime the index.php page is refreshed? won't it remember all this info until the session is closed?

 

I dunno I am really new at alot of this but learning alot too.

 

I know the people who wrote the code had no regard for efficientcy

 

now that you have a better idea of what is going on what do you suggest I try?

 

thanks for your time

 

Paul

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.