The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 12:36:16 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Building a subdomain or subfolder link based on a variable  (Read 1809 times)
xlspecial
n00b
*
Offline Offline

Posts: 2


View Profile
« on: August 02, 2007, 03:25:28 PM »

Ok, I am a complete noob at this php stuff but I am trying to modify some code. Currently it outputs links only for subfolders where I need it to use a variable (might not be correct terminology) to decide weather to build the link for a subfolder or subdomain.

It accesses my database and randomly chooses a domain then a random keyword. I'm about 50/50 with domains using subfolders and subdomains so I'd like to get this to detect which it is. In my domain table in the DB there is a column called ip_based. In this column a 0 indicates a subfolder domain while a 1 indicates a subdomain site.

Here is the code:

Code:
<?php


$base
=$_GET['base']; 
$base str_replace('.' ,''$base);
$base=$base."links.txt";
$temp=0;
$filename 'rdmlinks/'.$base;

//echo $filename;

if (file_exists($filename)) {
  } 
else {
$fh fopen($filename'w') or die("can't open file");


$nu=3;////number of loop to go trough all install -you can change it !


while ($temp $nu)
{
$temp++;
require "/home/xxxx/public_html/xxxx/includes/config.php";    
$db mysql_connect($config['db']['host'] . ":" $config['db']['port'],
$config['db']['username'], $config['db']['password']);
  if (!$db) {
print "<h1>Connect Error</h1>";
  }
  mysql_select_db($config['db']['name']);
  $z=0;
  $nb=rand(1,5); // random number of links default 1 to 5 links
  
while($z $nb){
//select Random domain
$query="SELECT domain_id,domain FROM domain ORDER BY rand() Limit 1";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i $num) {
$predomain_id=mysql_result($result,$i,"domain_id");
$domain_id $predomain_id;
$predomain=mysql_result($result,$i,"domain");
$domain $predomain;
$i++;
}
//select random kw from domain
$query="SELECT keyword FROM main_keywords WHERE domain_id=$domain_id ORDER BY rand() Limit 1";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i $num) {
$kw=mysql_result($result,$i,"keyword");
$kw2 str_replace('-' ,''$kw);
$kw str_replace(' ' ,'-'$kw);
$i++;
}
$stringData "<a href=\"http://www." $domain "/".$kw."\">" $kw2 "</a>";
fwrite($fh$stringData);
$stringData "\n";
fwrite($fh$stringData);
echo '<center>';
echo '';
echo ' ';
echo '</center>';
$z++;
}
mysql_close();
}
}

$file fopen($filename"r");

while (!
feof($file)) { // write file with data 
$k fgets($file1024);
$k str_replace('\\' '' $k);
echo '<center>';
echo $k;
echo '</center>';

}
?>

I want it to build the link like this if ip_based is a 0;

Code:
$stringData = "<a href=\"http://www." . $domain . "/".$kw."\">" . $kw2 . "</a>";

And like this if ip_based is a 1:

Code:
$stringData = "<a href=\"http://www." .$kw. "." . $domain . "/""\">" . $kw2 . "</a>";

It writes the output to a text file in rdmlinks folder.

Thanks for any help you might be able to offer on this. I'm trying to learn this stuff but am having a very hard time of it.
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: August 03, 2007, 05:38:07 PM »

Hey XL -

Just wanted you to know that I keep pressing "Mark Unread" on this post because I haven't had the time to think through it, but didn't want you to think you were being neglected Wink

I'll look at it soon,
/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!