Page 1 of 1

Can anybody please help me? I pay $20

Posted: Wed Jul 07, 2010 12:21 pm
by dominod
Hi

I am a newbie in PHP and have been trying to solve this problem for days without any luck.. I tested alot by myself, asked in plenty of forums and even asked my previous programmer for help without any luck..

So now I want your help and I will pay $30 via PayPal to the person who figure this out.

Here is the problem:

I am trying to redirect a page to another page when a certain keyword is submitted in a text field. Both the keywords and the URL“s it will redirect to will be pulled from a database.

My code looks like this:

Code: Select all

<?php

ini_set("display_errors", true);
error_reporting(-1);

header("Location: $redir");
exit;

include("connect.php");

$extract = mysql_query("SELECT * FROM engines");
$numrows = mysql_num_rows($extract);
$i = "0";
while ($row = mysql_fetch_array($extract))
{
$id=$row['id'];
$name[$i]=$row['name'];
$url[$i]=$row['url'];
$searchurl[$i]=$row['searchurl'];
$keyword[$i]=$row['keyword'];
$i++;
}

function wordsExist(&$string, $words) {
    foreach($words as &$word) {
        if(stripos($string, $word) !== false) {
            return true;
        }
    }
    return false;
}

function wordExist(&$string, $string) {
        if(stripos($string, $string) !== false) {
            return true;
    }
    return false;
}

{
	$keyword = preg_replace('/([a-zA-Z0-9]*(\s){0,1}):/','',$search);
	$shop = preg_replace('/:([a-zA-Z0-9]*(\s){0,1})/','',$search);
}

if (wordExist($search, $keyword))
{

	$redir = "http://domain.com"; //this should be a URL!
	break;
	}

elseif (wordsExist($search, array('http://'))) {
    $redir = $search; //this should be a URL!
}

elseif (wordsExist($search, array('.com','.net','.org','.aero','.asia','.biz','.cat','.coop','.edu','.gov','.info','.int','.jobs','.mil','.mobi','.museum','.name','.pro','.tel','.travel','.ac','.ad','.ae','.af','.ag','.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.ax','.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.er','.es','.et','.eu','.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gb','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gw','.gy','.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq','.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki','.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.me','.mg','.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rs','.ru','.rw','.sa','.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.su','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tl','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.wf','.ws','.ye','.yt','.za','.zm','.zw')))
{
	$redir = "http://$search"; //this should be a URL!
	}

elseif (wordsExist($search, array('tlf:')))
{

	$redir = "http://opplysning1890.no/index.php?q=$keyword&type=privat"; //this should be a URL!
	}

elseif (wordsExist($search, array(':')))
{
	echo "There is no search engine connected with <b>$shop</b>. If you want to suggest a search engine please <a href=\"suggest.php\">click here</a>. If you rather want to search in Google for <b>$keyword</b>, please  <a href=\"http://www.google.com/search?q=$keyword\">click here</a>.<br />";
	}

else
{
    $redir = "http://www.google.com/search?q=$search";
}
?>
When I submit the form it gives me the following error code:

Code: Select all

Notice: Undefined variable: redir in /home/haukaas/public_html/new/search.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at /home/haukaas/public_html/new/search.php:6) in /home/haukaas/public_html/new/search.php on line 6
This is where I am stuck :(

If you want to help me over MSN or Skype let me know and I will send you my info...

Thanks in advance

Re: Can anybody please help me? I pay $20

Posted: Wed Jul 07, 2010 12:25 pm
by dominod
BTW I have posted this in other forums as well so it is the first person who helps me who will get the cash..

http://www.phpfreaks.com/forums/index.p ... 507.0.html
http://forums.digitalpoint.com/showthread.php?t=1863556

Re: Can anybody please help me? I pay $20

Posted: Wed Jul 07, 2010 12:34 pm
by AbraCadaver
I would start by removing this:

Code: Select all

header("Location: $redir");
exit;

Re: Can anybody please help me? I pay $20

Posted: Wed Jul 07, 2010 12:39 pm
by dominod
But how can I then redirect to the page I want to redirect to?

Re: Can anybody please help me? I pay $20

Posted: Wed Jul 07, 2010 12:47 pm
by AbraCadaver
My bad. Actually, move that to the end of the script, just before the ?>.

Re: Can anybody please help me? I pay $20

Posted: Wed Jul 07, 2010 12:55 pm
by dominod
Problem solved by uldtot at http://forums.digitalpoint.com/showthread.php?t=1863556

Thanks alot for your help guys:D