473,765 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

redirect.php maligns redirection URL every time

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

if ($_GET['id']) {

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

// XML PARSE
$parser = xml_parser_crea te();
@xml_parse_into _struct($parser , $stuff, $redirectArray, $tags);
@xml_parser_fre e($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($redirect Array[$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><met a 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="p ath=studies&amp ;name=madonnacr ucifixion.txt"> </redirection><re direction
id="2" url="http://the-nordic-one.livejournal .com#alchemymem o
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 3530
On 26 Oct 2006 10:33:23 -0700, "comp.lang. php"
<ph************ **@gmail.comwro te:
$url = $redirectArray[$id]['attributes']['URL'];
if (trim($redirect Array[$id]['attributes']['QUERY_STRING']) !== '?')
$url .= '?';
$url .= preg_replace('/=/i', '=',
$redirectArr ay[$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($redirect Array[$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
7781
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. The obvious way to do this is by using the static Console type properties, In and Out. When trying to debug the app in the IDE however, this doesn't appear to work. I've edited the project properties and added the necessary text to the "command...
2
2870
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. We have the page designed so that if the user is not authenticated then they get redirected using Response Redirect method to the homapage.
13
2109
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 would like to have a php function handle displaying every page, for example, instead of: http://www.mysite.com/mypage.html you would call:
21
1850
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. Are there any way of (easily, without messing the site ;)) redirecting those links to the main site?
2
3655
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 provided (noos.fr) had trouble with ftp, so that access to my web pages became very problematic, mostly impossible. After 2 months and many unanswered complaints, I decided to buy my own domain, subscribe with a different host and transfer all my files...
6
2979
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 the best way to have all domain pages redirect to domain A? Right now I just have redirect code in each program on domain B to redirect to a maintenance page on domain A. Can I just write on program to solve this issue? Thanks.
8
4917
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 works great and is easy to set up, but at this point, the client (which is my client, who's working with the actual client) doesn't know what the new web host supports. In the interim, I want to do a bit of research myself on this to see if it's...
2
3380
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 by ASP.NET. I have a TreeView control with a hierarchical Category listing of products. Here is the code in selected node changed event: protected void CategoryTreeView_SelectedNodeChanged(object sender, EventArgs e) {
4
8151
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 up, it seems to be erased, if I remove the redirect, it does.
0
9398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.