Page 1 of 1

Works locally, blank live?!

Posted: Thu Dec 13, 2007 10:46 am
by JAB Creations
This works perfectly on my home machine though generates no errors, no redirects, no text, no headers, NOTHING live? Exact same code both at home and live.

Code: Select all

<?php
session_name ("member");
session_start();

error_reporting(E_ALL);
ini_set('display_errors',1);

$referer = basename($_SERVER['HTTP_REFERER']);
$domain = $_SERVER['HTTP_HOST'];
$refdomain = $_SERVER['HTTP_REFERER'];
$refdomain = preg_replace("/http:\/\//i", "", $refdomain);
$refdomain = preg_replace("/^www\./i", "", $refdomain );
$refdomain = preg_replace("/\/.*/i", "", $refdomain ); 

include "classes/mysql.class.php";
$class_mysql = new JAB_MySQL('classes/cache/');

include "classes/user.class.php";
$class_user = new JAB_User;

if (!empty($_POST) && $refdomain == $domain)
{
 if ($class_user->login($_POST)) {
  $_SESSION['loggedin'] = TRUE;
  header('Location: '.($_SERVER['HTTP_REFERER']));
  die();
  }
 else{
  die('Invalid Login: Try Again.');
 }
}
?>

Posted: Thu Dec 13, 2007 10:56 am
by feyd
What is the default setting for error_reporting and display_errors? You can run the following in a new file to find out.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
	$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>

Posted: Thu Dec 13, 2007 11:01 am
by JAB Creations
I'm not matching on the live site!

localhost
$refdomain = localhost
$domain = localhost
live site
$refdomain = jabcreations.com
$domain = http://www.jabcreations.com
So I need to figure out how to get the live domain to match...

Posted: Thu Dec 13, 2007 11:05 am
by JAB Creations
One of those many "I fixed my own problem" threads. 8)

The issue was to set my preg_replace syntax to both variables. Here is the code in conjunction with a test page linking to this one (to set the referer)...

Code: Select all

<?php
session_name ("member");
session_start();

error_reporting(E_ALL);
ini_set('display_errors',1);

$referer = basename($_SERVER['HTTP_REFERER']);
$domain = $_SERVER['HTTP_HOST'];
$domain = preg_replace("/http:\/\//i", "", $domain);
$domain = preg_replace("/^www\./i", "", $domain );
$domain = preg_replace("/\/.*/i", "", $domain ); 

$refdomain = $_SERVER['HTTP_REFERER'];
$refdomain = preg_replace("/http:\/\//i", "", $refdomain);
$refdomain = preg_replace("/^www\./i", "", $refdomain );
$refdomain = preg_replace("/\/.*/i", "", $refdomain ); 

include "classes/mysql.class.php";
$class_mysql = new JAB_MySQL('classes/cache/');

include "classes/user.class.php";
$class_user = new JAB_User;


if (!empty($_POST) && $refdomain == $domain)
{
 if ($class_user->login($_POST)) {
  $_SESSION['loggedin'] = TRUE;
  header('Location: '.($_SERVER['HTTP_REFERER']));
  die();
  }
 else{
  die('Invalid Login: Try Again.');
 }
}

echo '$refdomain = ' . $refdomain . '<br />';
echo '$domain = ' . $domain;

?>

Posted: Thu Dec 13, 2007 11:07 am
by feyd
Remove the "www." stripping from the referral, or do it to the host as well.