PHP Help

SpaceshipSpaceship
Watch

Spawn

Established Member
Impact
2
Hello i need some php help, i use the following code in the title of my website:

<title><?
if($q != ""){
echo "$q Name of my Website";
}
else{
echo "Name of my Website";
}
?></title>

Everything works fine, the problem however is when i want to add another line like this:

<title><?
if($q != ""){
echo "$q Name of my Website";
}
if($type != ""){
echo "$type Name of my Website";
}
else{
echo "Name of my Website";
}
?></title

So now when i go to the search page it looks like this (in the title): "$q Name of my Website$type Name of my Website", i have tryed to add some break codes, but just cant seem to get it working.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Are you wanting to show either $q or $type or do you want them both to show if they are both not empty?
 
0
•••
Well as it works now when someone do a search, it list that search at the bottom of the page for google to index, so when it gets indexed, it shows the search query in the title of the page for that search. I would also like to have the categories name in the title there is where the $type comes in, but wont work :/
 
0
•••
From what I understand, you can do something like this:

<title><?
if($q != ""){
echo "$q Name of my Website";
}
elseif($type != ""){
echo "$type Name of my Website";
}
else{
echo "Name of my Website";
}
?></title>

Unless $type happens to be undefined or null.

Or if you are trying to put them together:

if(($q != "")&&($type != "")){
echo "$q Name of my Website | $type Name of my Website";
}
elseif($q != ""){
echo "$q Name of my Website";
}
elseif($type != ""){
echo "$type Name of my Website";
}
else{
echo "Name of my Website";
}
 
0
•••
Thanks alot :)

This worked just as i wanted it :)

<title><?
if($q != ""){
echo "$q Name of my Website";
}
elseif($type != ""){
echo "$type Name of my Website";
}
else{
echo "Name of my Website";
}
?></title>
 
0
•••
I made a few modifications to cut out security risks, if data is being sent via form or url, and to prevent NOTICEs from appearing for undefined variables:

Code:
<title><?php
if(!empty($_REQUEST['q'])) {
	echo htmlspecialchars(strip_tags($_REQUEST['q'])) . ' Name of my Website';
} elseif(!empty($_REQUEST['type']))) {
	echo htmlspecialchars(strip_tags($_REQUEST['type'])) . ' of my Website";
} else{
	echo 'Name of my Website';
}
?></title>
 
0
•••
Thanks, i should realy use another script or have someone clean up the current one, as this one is quite old, from 2001, but it works just as i want :P
 
0
•••
It is good to see that the issue is solved. But i would like to ad that html statments such as break do not work for php. You have to either output a like a command. For example.
<?php echo "<br />";?> or use a return meta character such as \n at the end of line and new line will be started. I hope it helps.
 
0
•••
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back