homepage Welcome to WebmasterWorld Guest from 54.196.159.11
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Redirect vs Forward
iamvela




msg:4138083
 12:12 am on May 25, 2010 (gmt 0)

Is there a way to do PHP redirect, rather than PHP forward.

When we post a link to http://example.com on Facebook etc. it shows the meta tags on our index page and not on the actual page. I'd really like for the actual page to be pre-viewed (as in loaded).

The only explanation I can come up with is it has to do with doing a redirection as
header(location: $url);

I have tried to put a
header( "HTTP/1.1 301 Moved Permanently" );
before the redirect but to no avail.


Any ideas would be very much appreciated.

Thanks.
--

[edited by: dreamcatcher at 4:42 am (utc) on May 25, 2010]
[edit reason] Use example.com, thank you [/edit]

 

KevinH




msg:4138209
 5:19 am on May 25, 2010 (gmt 0)

This is what we use:

header("Location: http://example.com", TRUE, 302);

If you want a 301 (permanent) use this:

header("Location: http://example.com", TRUE, 301);


Make sure you put this line before ANY content or whitespace is printed or you'll get an error.

iamvela




msg:4138218
 5:54 am on May 25, 2010 (gmt 0)

Thats very helpful, when I tried that on a test.php file it works but once integrated with our code it still does not :(

Admin can we pls share the actual URL?

Matthew1980




msg:4138249
 7:32 am on May 25, 2010 (gmt 0)

Hi there iamvela,

It would be helpful to post the portion of code you have placed the header into, because if it works in your 'test.php' there must be something wrong with where or how you have placed the header in the context of your actual script.

And as KevinH correctly states, if there is anything (even whitespace) after the declaration, you will get an error. Usually if you are using a header(); it's a good method to kill the script directly after so that nothing downstream can be executed:-

//
//Rest of your code
//
header("Location: Someurl.com");
exit;

Cheers,
MRb

TheMadScientist




msg:4138440
 2:54 pm on May 25, 2010 (gmt 0)

When we post a link to http://example.com on Facebook etc. it shows the meta tags on our index page and not on the actual page. I'd really like for the actual page to be pre-viewed (as in loaded).

Could you define 'doesn't work' a bit more?
Is it working with the browser you are using?
If it is not doing anything have you emptied your cache?

Is it working with the browser and not FaceBook?
If it is you will probably need to link directly to the page if possible, because my guess is it's FB's system rather than the PHP redirect.

IOW: If you empty your cache and the browser redirects without PHP throwing a 'header already set' error, then it's a FaceBook issue, not a PHP issue.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved