Jump to content


Photo

header('HTTP/1.1 301 *CLOSED*


  • This topic is locked This topic is locked
5 replies to this topic

#1 StirCrazy

StirCrazy
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 30 April 2006 - 12:57 PM

I'm trying to get some simple code working and wondered if someone could help me.

Basicly what i need doing is below

<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$id);
exit;
?>

only some of the links contain www.domain.com and others contain [a href=\"http://www.domain.com\" target=\"_blank\"]http://www.domain.com[/a]

what I need is ...

if $id doesn't have http:// or https:// then add http:// and redirect
if $id does have http:// or https:// then redirect without changing anything.
if $id has no value then carry on with the rest of the code...


Does that make any sense?

S.C>

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 30 April 2006 - 05:06 PM

Here's a very basic validation example:

<?php
// Set $id first

if (!empty($id)) {  // Does $id contain something?

    // Add http:// when $id doesn't start with http:// or https://
    if (!preg_match('/^https?:\/\//i', $id)) {
        $id = 'http://' . $id;
    } 
    
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . $id);
    exit;
}

// Carry on with rest of code

?>

Ideally, the $id should be checked more thoroughly to conform to URL standards.


#3 StirCrazy

StirCrazy
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 30 April 2006 - 05:43 PM

toplay your a star! thank you ~
when you say URL standards what do you mean? I only chose $id because im guessing google will think it's a session id and not follow the link (which is what I want).
(e.g [a href=\"http://www.domain.com/link.php?id=***url***\" target=\"_blank\"]http://www.domain.com/link.php?id=***url***[/a] )

Thanks again.

S.C>

#4 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 30 April 2006 - 05:54 PM

[!--quoteo(post=370141:date=Apr 30 2006, 10:43 AM:name=StirCrazy)--][div class=\'quotetop\']QUOTE(StirCrazy @ Apr 30 2006, 10:43 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
toplay your a star! thank you ~
when you say URL standards what do you mean? I only chose $id because im guessing google will think it's a session id and not follow the link (which is what I want).

Thanks again.

S.C>
[/quote]
I just mean that it conforms to RFC regs. You know, make sure that it's something like www.example.com rather just some garbage data (i.e. $id="I'm being silly"). Data should always be validated very strictly, especially if it's being passed in the URL (GET method).

You can search for regular expressions at this site. I don't know, search for www, domain, or URL, or something similar:

[a href=\"http://regexlib.com/Search.aspx?k=www\" target=\"_blank\"]http://regexlib.com/Search.aspx?k=www[/a]

[a href=\"http://regexlib.com/Search.aspx?k=domain\" target=\"_blank\"]http://regexlib.com/Search.aspx?k=domain[/a]

#5 codecontractor

codecontractor
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 15 May 2006 - 11:02 PM

Here's a cool tool if you want to want to confirm your headers are actually working properly.

Firefox HeaderGetter Extension

-Ben


#6 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 16 May 2006 - 12:07 AM

[!--quoteo(post=374147:date=May 15 2006, 04:02 PM:name=codecontractor)--][div class=\'quotetop\']QUOTE(codecontractor @ May 15 2006, 04:02 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Here's a cool tool if you want to want to confirm your headers are actually working properly.

Firefox HeaderGetter Extension

-Ben
[/quote]
There is no advertising allowed in these forums. Since you wrote this extension, I consider it advertising. You're allowed to put stuff like that in your signature though.

Also, this topic has been solved and the last post was over 2 weeks old and IMO is generally bad taste to post at that point.

I prefer a much better extension that does a whole lot more called LiveHTTPHeaders for Firefox:

[a href=\"http://livehttpheaders.mozdev.org/\" target=\"_blank\"]http://livehttpheaders.mozdev.org/[/a]

This topic is now closed.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users