reunir deux fichier php

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : reunir deux fichier php

par adri » 15 août 2005, 19:56

une autre idée serait d'envoyer une variable _GET ou _POST genre points=400

et dans ton script tu mets juste un petit if au moment crucial de l'opération. Comme les deux pages sont quasiment identiques, c'est plus mieux de généraliser et de mettre une bête petite condition, en plus en faisant ça, pour actualiser ton code ce sera égallement plus facile et plus direct.

voilà

par JazzFinder » 14 août 2005, 20:30

Effectivement, c'est pas très clair. Tu devrais peut être revoir ton système d'attribution de points. Tu pourrais entreveoir, par exemple, de ne faire marcher qu'un seul fichier contenant des conditions particulières, qui chacune, ne fera tourner qu'un script. C'est une idée parmi d'autres. Bonne chance.

par ma_pomme » 13 août 2005, 17:30

et bien en faite le premier fichier donne 850 point quand il est activé et apres confirmation et le second fait la meme chose sauf qu'il ne donne que 400 point et j'aurai voulu en faire un seul qui donne soit 850 ou 400 suivant la partie du script qui serai appelé.

je sais que je suis pas tres clair mais je fais de mon mieux :?

par JazzFinder » 13 août 2005, 17:00

Sois un peu plus précis. Qu'est ce que tu veux dire par 'réunir'? Faire un 'merge'? Vérifier lequel contient cette variable additionnelle? Garder le plus récent? Vérifier lequel a une plus grande taille de fichier? Etc...

reunir deux fichier php

par ma_pomme » 13 août 2005, 16:29

voila mon probème je souhaiterai réunir deux fichier php qui sont identique a une variable pres. je precise que c'est pour un forum phpbb. Je ne sais vraiment pas comment faire :? :?

1er fichier
<?php

define('IN_PHPBB', true);

$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_points.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

//
// Program Start
//
if (isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']))
{
	$mode = (isset($HTTP_POST_VARS['mode'])) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
}
else
{
	$mode = '';
}

$user_id = (isset($HTTP_GET_VARS[POST_USERS_URL])) ? intval($HTTP_GET_VARS[POST_USERS_URL]) : 0;

$template->set_filenames(array(
	'body' => 'achat.tpl')
);

//Start
if ($userdata['user_id'] == ANONYMOUS)
	{
		$redirect = "pointscp.$phpEx";
		$redirect .= (isset($user_id)) ? '&user_id=' . $user_id : '';
		header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
	}
	if (isset($HTTP_POST_VARS['submit']))
	{
		if (empty($HTTP_POST_VARS['username']) && empty($HTTP_POST_VARS['mass_username']))
		{
			$error = true;
			$error_msg .= $lang['Points_no_username'];
		}
		else
		{
			$user_id = get_userid_from_name($HTTP_POST_VARS['username']);
			
			if (empty($user_id) && empty($HTTP_POST_VARS['mass_username']))
			{
				$error = true;
				$error_msg = $lang['No_such_user'];
			}
			else
			{
				$user_id_list = array();
				$user_id_list[] = $user_id;

				if (!empty($HTTP_POST_VARS['mass_username']))
				{
					$mass_usernames = explode("\n", $HTTP_POST_VARS['mass_username']);

					foreach ($mass_usernames as $username)
					{
						$username = trim($username);

						if (!empty($username))
						{
							$user_id_list[] = get_userid_from_name($username);
						}
					}
				}
				
				$user_id_list = array_unique($user_id_list);
			}
		}

		if (isset($error))
		{
			$template->set_filenames(array(
				'reg_header' => 'error_body.tpl')
			);
			$template->assign_vars(array(
				'ERROR_MESSAGE' => $error_msg)
			);
			$template->assign_var_from_handle('ERROR_BOX', 'reg_header');
		}
		else
		{
			$amount = abs(intval($HTTP_POST_VARS['amount']));

			$method_function = ($HTTP_POST_VARS['method']) ? 'add_points' : 'subtract_points';

			foreach ($user_id_list as $user_id)
			{
				if (!empty($user_id))
				{
					$method_function($user_id, $amount);
				}
			}

			$loc = (isset($HTTP_POST_VARS['location']) && !empty($HTTP_POST_VARS['location'])) ? $HTTP_POST_VARS['location'] : append_sid("index.$phpEx");
			
			$template->assign_vars(array(
				'META' => '<meta http-equiv="refresh" content="3;url=' . $loc . '">')
			);

			$msg = $lang['Credit'];
			message_die(GENERAL_MESSAGE, $msg);
		}
	}

	$s_username = (!empty($user_id)) ? get_username_from_id($user_id) : '';
	$location = (!isset($HTTP_POST_VARS['location'])) ? $HTTP_SERVER_VARS['HTTP_REFERER'] : $location;
	$s_hidden_fields = '<input type="hidden" name="location" value="' . $location . '">';

	$template->assign_vars(array(
		'L_SUBMIT' => $lang['Confirm'],
		'USER_LOGUED' => $userdata['username'],
		'USERNAME' => $s_username,
		'MERCI' => $lang['merci'],
		'VALEUR' => $lang['valeur_850'],
		
		'S_HIDDEN_FIELDS' => $s_hidden_fields,
		'S_POST_ACTION' => append_sid("achat_850.$phpEx", true))
	);
	$template->assign_block_vars('switch_points_cp', array());


//
// Start output of page
//
$page_title	= $lang['Points_sys'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

//
// Generate the page
//
$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>
2éme fichier
<?php


define('IN_PHPBB', true);

$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_points.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

//
// Program Start
//
if (isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']))
{
	$mode = (isset($HTTP_POST_VARS['mode'])) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
}
else
{
	$mode = '';
}

$user_id = (isset($HTTP_GET_VARS[POST_USERS_URL])) ? intval($HTTP_GET_VARS[POST_USERS_URL]) : 0;

$template->set_filenames(array(
	'body' => 'achat.tpl')
);

//Start
if ($userdata['user_id'] == ANONYMOUS)
	{
		$redirect = "pointscp.$phpEx";
		$redirect .= (isset($user_id)) ? '&user_id=' . $user_id : '';
		header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
	}
	if (isset($HTTP_POST_VARS['submit']))
	{
		if (empty($HTTP_POST_VARS['username']) && empty($HTTP_POST_VARS['mass_username']))
		{
			$error = true;
			$error_msg .= $lang['Points_no_username'];
		}
		else
		{
			$user_id = get_userid_from_name($HTTP_POST_VARS['username']);
			
			if (empty($user_id) && empty($HTTP_POST_VARS['mass_username']))
			{
				$error = true;
				$error_msg = $lang['No_such_user'];
			}
			else
			{
				$user_id_list = array();
				$user_id_list[] = $user_id;

				if (!empty($HTTP_POST_VARS['mass_username']))
				{
					$mass_usernames = explode("\n", $HTTP_POST_VARS['mass_username']);

					foreach ($mass_usernames as $username)
					{
						$username = trim($username);

						if (!empty($username))
						{
							$user_id_list[] = get_userid_from_name($username);
						}
					}
				}
				
				$user_id_list = array_unique($user_id_list);
			}
		}

		if (isset($error))
		{
			$template->set_filenames(array(
				'reg_header' => 'error_body.tpl')
			);
			$template->assign_vars(array(
				'ERROR_MESSAGE' => $error_msg)
			);
			$template->assign_var_from_handle('ERROR_BOX', 'reg_header');
		}
		else
		{
			$amount = abs(intval($HTTP_POST_VARS['amount']));

			$method_function = ($HTTP_POST_VARS['method']) ? 'add_points' : 'subtract_points';

			foreach ($user_id_list as $user_id)
			{
				if (!empty($user_id))
				{
					$method_function($user_id, $amount);
				}
			}

			$loc = (isset($HTTP_POST_VARS['location']) && !empty($HTTP_POST_VARS['location'])) ? $HTTP_POST_VARS['location'] : append_sid("index.$phpEx");
			
			$template->assign_vars(array(
				'META' => '<meta http-equiv="refresh" content="3;url=' . $loc . '">')
			);

			$msg = $lang['Credit'];
			message_die(GENERAL_MESSAGE, $msg);
		}
	}

	$s_username = (!empty($user_id)) ? get_username_from_id($user_id) : '';
	$location = (!isset($HTTP_POST_VARS['location'])) ? $HTTP_SERVER_VARS['HTTP_REFERER'] : $location;
	$s_hidden_fields = '<input type="hidden" name="location" value="' . $location . '">';

	$template->assign_vars(array(
		'L_SUBMIT' => $lang['Confirm'],
		'USER_LOGUED' => $userdata['username'],
		'USERNAME' => $s_username,
		'MERCI' => $lang['merci'],
		'VALEUR' => $lang['valeur_400'],
		
		'S_HIDDEN_FIELDS' => $s_hidden_fields,
		'S_POST_ACTION' => append_sid("achat_400.$phpEx", true))
	);
	$template->assign_block_vars('switch_points_cp', array());


//
// Start output of page
//
$page_title	= $lang['Points_sys'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

//
// Generate the page
//
$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>