MyBB Community Forums

Full Version: PHP - 2 Values to 1 Variable?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hey, is it possible to assign two different values to 1 variable (without an if..else statement)?

Thanks Smile
No, it would confuse the system. Only show 1 variable.
An array...? I believe.
Well, here's what I want:

I have a directory. The backlink checker currently checks for a backlink under a certain URL. In this case, it is defined by:

$cfg['scan_needle'] = 'mydomain.com';

I want to set it so that I could put two domains there, so people can choose which domain they want to link back to. Something like:

$cfg['scan_needle'] = 'mydomain.com' || 'myotherdomain.com';

Although I'm pretty sure the above doesn't work...
Ah its on the tip of my tongue...there might be a way to do this but I dont know...Can't remember.
I'm sure this is important to. This is a script inside of the submission processor:

	if (!$errors && $cfg['scan'])
	{
		$found_needle = false;	
		$url_2 = @parse_url($hint);
		if (isset($url_2['host']) && $url_2['host'] == $url['host'])
		{
			$tmp = "http://".$url['host'];
			if (isset($url_2['path']))
				$tmp .= $url_2['path'];
			if (isset($url_2['query']))
				$tmp .= '?'.$url_2['query'];
			$data = file_get_contents($tmp);
			if (stristr($data, $cfg['scan_needle']) !== false)
				$found_needle = true;
		}
		if (!$found_needle)
		{
			$scanner = new Scanner();
			$scanner->init($proxy, $cfg['scan_needle']);
			$found_needle = $scanner->scan($cfg['scan_timeout']);
		}
		if (!$found_needle)
			$errors[] = 'We can\'t find a link back to us on your website.';
I think the line is:

$scanner->init($proxy, $cfg['scan_needle']);

$cfg['scan_needle'] is the URL that I declared earlier in config.php. Can I replace this so that it scans two URLs? Would this simply work?

$scanner->init($proxy, $cfg['scan_needle']);
$scanner->init($proxy, $cfg['scan_needle2']);
Maybe $var = "this|that";
then $var = explode("|", $var);
(2009-09-07, 02:56 AM)xiofire Wrote: [ -> ]Maybe $var = "this|that";
then $var = explode("|", $var);

Where would I put that? Would this work?

$cfg['scan_needle'] = 'domain1.com';
$cfg['scan_needle_2'] = 'domain2.com';

$var = "$cfg['scan_needle']|$cfg['scan_needle_2']";
$var = explode("|", $var);

And then I would replace all instances of $cfg['scan_needle'] in that PHP file with $var?
Yes, but here is a cleaner version:
<?php
$cfg['scan_needle'] = 'domain1.com';
$cfg['scan_needle_2'] = 'domain2.com';

$var = $cfg['scan_needle']."|".$cfg['scan_needle_2'];
$var = explode("|", $var);
?>
Here's what I did:

$linkback = $cfg['scan_needle']."|".$cfg['scan_needle_2'];
$linkback = explode("|", $linkback);
		if (isset($url_2['host']) && $url_2['host'] == $url['host'])
		{
			$tmp = "http://".$url['host'];
			if (isset($url_2['path']))
				$tmp .= $url_2['path'];
			if (isset($url_2['query']))
				$tmp .= '?'.$url_2['query'];
			$data = file_get_contents($tmp);
			if (stristr($data, $linkback) !== false)
				$found_needle = true;
		}

		if (!$found_needle)
		{
			$scanner = new Scanner();
			$scanner->init($proxy, $linkback);
			$found_needle = $scanner->scan($cfg['scan_timeout']);
		}
But now it doesn't work at all.
Pages: 1 2 3