redirecting[SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

redirecting[SOLVED]

Post by mayanktalwar1988 »

location.php

Code: Select all

 
<?php
include("mysql_connect.php");
$id =$_GET['id'];
$sql=mysql_query("SELECT * FROM topics WHERE id='".$id."'");
if($row=mysql_fetch_array($sql))
header("Location:{$row['webpage']}");
mysql_close($con);
?> 
 
with the above scrpt it is redirecting me to http://localhost/pro1/facebook.com istead of facebook.com
the link with which this script get intiated is like this localhost/pro/location.php?id=21
there is a corresponding webpage in the table coresponding to that particular unique id...how to make this script go to http://www.domain.com
instead of localhost/pro/domain.com
Last edited by mayanktalwar1988 on Mon Sep 28, 2009 3:20 pm, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: redirecting

Post by requinix »

Your links have to say "http://facebook.com". You can probably add the "http://" automatically with

Code: Select all

header("Location: http://{$row['webpage']}");
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: redirecting

Post by mayanktalwar1988 »

still no luck
similar result http://localhost/pro1/facebook.com
i am now clueless..i am providing facebook.com from database but it is ending in http://localhost/pro1/facebook.com
uyewq
Forum Newbie
Posts: 22
Joined: Thu Sep 17, 2009 6:21 am

Re: redirecting

Post by uyewq »

Hi,
not sure, only an idea but, in your db, maybe you should keep your url with double quotes or vice versa...
You can ask your IT consultant for sure, he/she may be can tell something about server config..
Check your code (extracts from db) if PHP_% variable exist before it.

if these doesn't solve you can retouch your echo with string replacing functions to crop unwanted part(s) of course.
Bye
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: redirecting

Post by Ollie Saunders »

Replace:

Code: Select all

header("Location:{$row['webpage']}");
with:

Code: Select all

var_dump(error_reporting(), headers_sent(), $row);
What output do you get?
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: redirecting

Post by mayanktalwar1988 »

ok wait doing it
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: redirecting

Post by mayanktalwar1988 »

it ends up with
object not found page 404 error
with this url http://localhost/pro1/facebook.com
on one of links i am testing out
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: redirecting

Post by Ollie Saunders »

OK, then you're not even running the code that you posted. Does it help to know that? If not, I'm not sure what else I can suggest. If you don't know what files are being run, where, I can't help you. I wonder if you're using frames, which are complicating things.
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: redirecting

Post by mayanktalwar1988 »

ollie i have coded every bit myself of the scripts ..which are in pro1 folder
i dont know what is happing with this just with this i used similar thing in other scripts
i dont know why it is addind locahost/pro1 in directing links
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: redirecting

Post by Ollie Saunders »

What OS are you running?
What web server are you running?
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: redirecting

Post by mayanktalwar1988 »

now it is getting serious window xp server xxamppp on localhost
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: redirecting

Post by Ollie Saunders »

OK, that means your web server is Apache. If you can, try and find out what the document root of Apache is configured to. I guess, there'll be some configuration system for XAMPP where that is set, so, you can find out from there.

Also, what is the full path of the PHP script?
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: redirecting

Post by mayanktalwar1988 »

full path is localhost/pro1 i think you are asking for this under htdocs
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: redirecting

Post by Ollie Saunders »

I'm after the full path of the script, as it is stored on your filesystem. You should be able to find that by right-clicking on the file in explorer, choosing properties, and copy-pasting the path from that properties dialog. The path should include the file's name as well, if it doesn't, please tell me that too.

Also, could you give me the sam (full path), for that htdocs directory.

Finally, now that I think of it, I should ask if you know if you're doing any mod_rewrite stuff?
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: redirecting

Post by mayanktalwar1988 »

hey ollie
i got it it was mine mistake actuallyyyy
i enetred http://www.facebook.com previously it was just facebook.com obiviously with www ahead of it now its fine thank you everyone who responded to my pm
Last edited by mayanktalwar1988 on Mon Sep 28, 2009 3:17 pm, edited 2 times in total.
Post Reply