StirCrazy Posted April 30, 2006 Share Posted April 30, 2006 I'm trying to get some simple code working and wondered if someone could help me.Basicly what i need doing is below<?phpheader('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> Link to comment Share on other sites More sharing options...
toplay Posted April 30, 2006 Share Posted April 30, 2006 Here's a very basic validation example:[code]<?php// Set $id firstif (!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?>[/code]Ideally, the $id should be checked more thoroughly to conform to URL standards. Link to comment Share on other sites More sharing options...
StirCrazy Posted April 30, 2006 Author Share Posted April 30, 2006 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> Link to comment Share on other sites More sharing options...
toplay Posted April 30, 2006 Share Posted April 30, 2006 [!--quoteo(post=370141:date=Apr 30 2006, 10:43 AM:name=StirCrazy)--][div class=\'quotetop\']QUOTE(StirCrazy @ Apr 30 2006, 10:43 AM) [snapback]370141[/snapback][/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] Link to comment Share on other sites More sharing options...
codecontractor Posted May 15, 2006 Share Posted May 15, 2006 Here's a cool tool if you want to want to confirm your headers are actually working properly.Firefox HeaderGetter Extension-Ben Link to comment Share on other sites More sharing options...
toplay Posted May 16, 2006 Share Posted May 16, 2006 [!--quoteo(post=374147:date=May 15 2006, 04:02 PM:name=codecontractor)--][div class=\'quotetop\']QUOTE(codecontractor @ May 15 2006, 04:02 PM) [snapback]374147[/snapback][/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. Link to comment Share on other sites More sharing options...
Recommended Posts