Welcome Guest, Not a member yet? Register   Sign In
adding www to address(help needed)
#1

[eluser]plosey[/eluser]
I have function to get the current address(below) if it does not have www. on frot of the domain i want to add it and rerun the query.

This query is looking to see if the domain matches a domain in my database (all domains in the database are www.example.com not example.com) so if a user enters example.com i want the query to look for www.example.com not example.com lol hope that makes since.

can anyone help me fix my function below to accomplish this?

$url = $_SERVER['HTTP_HOST'];
$data['result'] = $this->db->where('url', $url);
$data['result'] = $this->db->get('sites');
if ($this->db->count_all_results() == 1) {
return $data['result'];
} else {
$url = 'www.'.$_SERVER['HTTP_HOST'];
$data['result'] = ''; // same resulte with or without this line
$data['result'] = $this->db->where('url', $url);
$data['result']=$this->db->get('sites');
return $data['result'];
}
#2

[eluser]CroNiX[/eluser]
try
Code:
...
} else {
  $url = ‘www.’.$_SERVER[‘HTTP_HOST’];
  $this->db->free_result();  //clear it for new query
  $this->db->where(‘url’, $url);  //don't need to assign this to a variable yet
  $data[‘result’]=$this->db->get(‘sites’);
  return $data[‘result’];
  }

However, I think it would be best to check the first 3 chars are www before you run the query initially, if it isn't add it and run it. Then you will always only have 1 query run instead of possibly two.
#3

[eluser]plosey[/eluser]
ty for the code and the idea on the bottom. that makes more since on running one query.
#4

[eluser]CroNiX[/eluser]
like
Code:
$url = $_SERVER[‘HTTP_HOST’];
if(strtolower(substr($url, 0, 3) !== 'www'))
{
   $url = 'www.' . $url;
}
//run query
#5

[eluser]plosey[/eluser]
ty that works great.




Theme © iAndrew 2016 - Forum software by © MyBB