Current location: Hot Scripts Forums » Programming Languages » PHP » What is wrong with this code?


What is wrong with this code?

Reply
  #1 (permalink)  
Old 06-06-06, 02:47 PM
silvercover's Avatar
silvercover silvercover is offline
Wannabe Coder
 
Join Date: Aug 2004
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
What is wrong with this code?

I have 5 domains which i want each to redirect to certain folder on one basic host.here is the script i wrote for that:

PHP Code:

<?


$url
=$_SERVER["HTTP_REFERER"];
if (
$url="http://www.sanatrooz.com") {
header("Location: http://www.dynaprocess.com/sanatrooz");
exit;
}
$url=$_SERVER["HTTP_REFERER"];
if (
$url="http://www.sanatiran.net" ){
header("Location: http://www.dynaprocess.com/sanatiran");
exit;
}
$url=$_SERVER["HTTP_REFERER"];
if (
$url="http://www.itsanat.com") {
header("Location: http://www.dynaprocess.com/itsanat");
exit;
}
$url=$_SERVER["HTTP_REFERER"];
if (
$url="http://www.dynaitsolution.com") {
header("Location: http://www.dynaprocess.com/itsolution");
exit;
}

?>

basic host is set with http://www.dynaprocess.com.
the problem is when i check this script it always redirects me to http://www.dynaprocess.com/sanatrooz

What is wrong?
Thanks in advance.

Last edited by Christian; 06-06-06 at 03:08 PM.
Reply With Quote
  #2 (permalink)  
Old 06-06-06, 02:51 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
when comparing stuff you have to use == not = . it's a common mistake . so this is how it should be:
PHP Code:

$url $HTTP_REFERER;

if(
$url == "http://www.dynaprocess.com"){
//do stuff

BTW: you can place all your code in just 1 if-structure, instead of seperated if's

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 06-06-06, 03:24 PM
silvercover's Avatar
silvercover silvercover is offline
Wannabe Coder
 
Join Date: Aug 2004
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Oh! what a mistake!
I made it correct but this time it shows a blank page!
Reply With Quote
  #4 (permalink)  
Old 06-06-06, 03:36 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
$HTTP_REFERER has the value of the page of which you just came. so if you just fill in "http://www.dynaprocess.com" in your url-field, there's no HTTP_REFERER and it will not redirect you to the specified directory

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 06-07-06, 01:21 AM
silvercover's Avatar
silvercover silvercover is offline
Wannabe Coder
 
Join Date: Aug 2004
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

I know about HTTP_REFERER. I put for example in http://www.sanatrooz.com address bar but again it shows me a blank page!

Thank you for your reply.
Reply With Quote
  #6 (permalink)  
Old 06-07-06, 05:22 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
what's the script on the index page of http://www.sanatrooz.com ?
you have to send a header to the page where you placed the script you posted here.
if you're just hoping that the page will be redirect miraculously, you're gonna have to wait a very long time .

as i said: HTTP_REFERER only has a value if you redirect someone from one page to another. so if you just fill in http://www.sanatrooz.com, in your browser, and you don't set a header in that page, nothing is set in the HTTP_REFERER variable

Greet,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #7 (permalink)  
Old 06-07-06, 11:49 AM
duesi's Avatar
duesi duesi is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 225
Thanks: 0
Thanked 0 Times in 0 Posts
But where do you run this script?
As UnrealEd points out, you need a script on

http://www.sanatrooz.com,
http://www.sanatiran.net
and
http://www.dynaitsolution.com

which redirect to your script (which renders your script pretty useless, as you need those 3 others).

Certainly, mod_rewrite would be nicer, if your servers support it.
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Cheers,
Dani
__________________
Duesi

"One of the great skills in using any language is knowing what not to use, what not to say" (Ron Jeffries)

http://www.swissbytes.de
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
what's wrong with this code hossamhamdi1986 PHP 3 02-27-06 07:42 AM
what's wrong with this code? hazarus PHP 6 02-23-05 11:19 PM
Not loading from MySQL database, i dont know whats wrong with the code alfrin PHP 5 02-12-05 03:26 PM
What's wrong with this code? whoknow Visual Basic 3 10-02-04 09:03 PM
something wrong with this code superman PHP 3 07-06-03 10:55 PM


All times are GMT -5. The time now is 07:16 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.