473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

redirect.php maligns redirection URL every time

[PHP]
require_once("/users/ppowell/web/php_global_vars.php");

if ($_GET['id']) {

// INITIALIZE VARS
$fileID = @fopen("$userPath/xml/redirect.xml", 'r');
$stuff = @fread($fileID, @filesize("$userPath/xml/redirect.xml"));
@fclose($fileID);

// XML PARSE
$parser = xml_parser_create();
@xml_parse_into_struct($parser, $stuff, $redirectArray, $tags);
@xml_parser_free($parser);
/*------------------------------------------------------------------------------------------
This will assume that the entire 3-dim XML-parsed array will have
as its outer key the
same ID value found in the 'id' attribute in the innermost array.
This means you cannot
ever delete any row from redirect.xml unless you renumber!

-------------------------------------------------------------------------------------------*/

$url = $redirectArray[$id]['attributes']['URL'];
if (trim($redirectArray[$id]['attributes']['QUERY_STRING']) !== '?')
$url .= '?';
$url .= preg_replace('/=/i', '=',
$redirectArray[$id]['attributes']['QUERY_STRING']);
$url = preg_replace('/\/$/', '', $url); // REMOVE TRAILING / TO
ACCOMMODATE QUERY STRING AND/OR ANCHOR

if (preg_match('/^http/i', $url)) {
echo "<script type=\"text/javascript\">\n<!--\n location.href=\"" .
str_replace('"', '&quot;', $url) . "\";\n //-->\n</script>\n" .
"<noscript><meta http-equiv=\"Refresh\" content=\"0:URL=" .
str_replace('"', '&quot;', $url) . "\"></noscript>\n";
}

}

[/PHP]

If the URL happens to be this:

http://the-nordic-one.livejournal.co...memory10242006

Instead it winds up looking like this every single time:

http://the-nordic-one.livejournal.co...emory10242006?

I know for a fact that redirect.xml has the correct information:

<pre>
<?xml version="1.0" encoding="utf-8" ?><redirections><redirection
id="1"
url="http://valsignalandet.com/http://valsignalandet.com/cgi-bin/cgiwrap/ppowell/te
xt.cgi"
query_string="path=studies&amp;name=madonnacrucifi xion.txt"></redirection><redirection
id="2" url="http://the-nordic-one.livejournal.com#alchemymemo
ry10242006" query_string="?"></redirection></redirections>
</pre>

But the URL is maligned every single time upon redirection. Is there a
way to prevent this from happening?

Thanx
Phil

Oct 26 '06 #1
1 3494
On 26 Oct 2006 10:33:23 -0700, "comp.lang.php"
<ph**************@gmail.comwrote:
$url = $redirectArray[$id]['attributes']['URL'];
if (trim($redirectArray[$id]['attributes']['QUERY_STRING']) !== '?')
$url .= '?';
$url .= preg_replace('/=/i', '=',
$redirectArray[$id]['attributes']['QUERY_STRING']);
$url = preg_replace('/\/$/', '', $url); // REMOVE TRAILING / TO
ACCOMMODATE QUERY STRING AND/OR ANCHOR

If the URL happens to be this:

http://the-nordic-one.livejournal.co...memory10242006

Instead it winds up looking like this every single time:

http://the-nordic-one.livejournal.co...emory10242006?
It appears that the code is missing a set of curly braces; this is
causing the first call to preg_match() to fire unconditionally, which
means that the query string is always going to be appended to the URL
(even if it's only '?').

Try this:

$url = $redirectArray[$id]['attributes']['URL'];
if (trim($redirectArray[$id]['attributes']['QUERY_STRING']) !== '?') {
$url .= '?';
$url .= preg_replace('/=/i', '=',
$redirectArray[$id]['attributes']['QUERY_STRING']);
}
$url = preg_replace('/\/$/', '', $url); // REMOVE TRAILING /

hth

-
Remove mypants to email.
<http://www.shaunc.com/>
Oct 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
2
by: Dr. Paul Caesar - CoullByte (UK) Limited | last post by:
Hi, I have created a Logout ASP.NET application using Forms Authentication. When a user logs out they get a confirmation page confirming logout and a button to click to return to the homepage....
13
by: Stephen Kay | last post by:
Is there a way to redirect every single page on an existing web site through a php function? In other words, say I have a whole functional HTML web site, never written to use any php. Now I...
21
by: John | last post by:
Hi, I updated a site and changed the file extensions from .html to .php. Now i noticed that the google does find the old .html pages but since they're not there anymore... they can't be found....
2
by: =?ISO-8859-1?Q?Fran=E7ois_de_Dardel?= | last post by:
I am not sure if this is the proper forum, but I always found very helpful information here and I would like to have the advice of experts. Just before new year (end Dec 2006), my internet...
6
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, We have two sites hosted on different servers and we have many pages on domain A which has many links(asp programs) to domain B. My question is if domain B server is in trouble, what is...
8
by: Darrel | last post by:
I'm helping convert a 300+ page .html site into an ASP.net site. The client wants to set up 301 redirects for all of the old html pages. I've used ISAPI for this type of thing in the past, as it...
2
by: daveh551 | last post by:
Okay, I asked a question a week or so ago asking for an explanation on relative URL's and the "~" symbol, and several people explained that the "~" is only usable when the URL is going to be parsed...
4
by: newsgroup.poster | last post by:
I need to set a custom http header before perform http redirection. I do response.AppendHeader("aCustomHeader", "aCustomValue") response.Redirect("anUrl") and my added header doesn't show...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.