Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 27th, 2006, 2:30 PM   #1
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3 kruptof is on a distinguished road
Script problem or platform conversion error

i wrote this script on my windows box:
use CGI;
$results=new CGI;

$comment=$results->param("comments");
$name=$results->param("name");
open(DAT,">>Comments.txt");
$i=60;
$j=0;
$szlen=length $comment;
print DAT $name;
print DAT "\n";

if($szlen<60)
{
	print DAT $comment."\n";
}
else
{
	
	while($i<=$szlen)
	{
		print DAT substr($comment,$j,$i)."\n";
		$j=$i;
		$i+=60;
	}
	if($i<$szlen)
	{
		print DAT substr($comment,$i,$$szlen-$i)."\n";
	}
}
close(DAT);

print "Content-type:text/html\n\n";

and i uploaded to my hosting company's linux server, but instead of getting a newline were i was expecting a new line i got this small rectangle between the texts, for example this the output on my windows box:
Test
Test

and this is the output on my server's linux box:
Test
Test
even when i type it in here it converts to a newline...any ways this is how the above is supposed to look "Test [] Test" (something like that). So
can some please tell me why this is. I thank you in advance for your replies.
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 27th, 2006, 5:17 PM   #2
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3 kruptof is on a distinguished road
Redirect Problem

okay after some googling and alot of cursing and head scatching i found an alternative to this problem, which seemed to help, so decided to test this, so halfway through my testing i said "i wonder if i refresh the page what would happen", well i found out, it wrote to the file again and the same thing was outputted twice, then i thought how about i redirect the user to another page, so i tried, but no matter what page i redirected the user to i ke getting the 404 page not found page, i even tried using full paths, but still 404,does any body know what on earth is happening here, any help is greatley appreciated.

Regards, Kruptof
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 28th, 2006, 9:26 AM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Windows uses "\r\n" as its linebreak. Linux and other Unix-like systems use "\n". A simple substitution should convert between the two (s/\n/\r\n/g).

As for the redirect - can I see your redirection code?
Arevos is offline   Reply With Quote
Old Jul 28th, 2006, 12:32 PM   #4
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3 kruptof is on a distinguished road
thanks Arevos......................ok here is the code for the redirection.....no matter what address i put in i will always get the 404 error:
#!/usr/bin/perl
use CGI;
$results=new CGI;

$comment=$results->param("comments");
$name=$results->param("name");
open(DAT,">>Comments.txt");
$i=60;
$j=0;
$szlen=length $comment;
print DAT $name."<br>";
print DAT "\n";

if($szlen<60)
{
	print DAT $comment."<br>";
}
else
{
	
	while($i<=$szlen)
	{
		print DAT substr($comment,$j,$i)."<br>";
		$j=$i;
		$i+=60;
	}
	if($i<$szlen)
	{
		print DAT substr($comment,$i,$$szlen-$i)."<br>";
	}
}
close(DAT);
open(DAT,"Comments.txt");
my @cont=<DAT>;
close(DAT);
print "location: home.html"; #<- this is the RELOCATion PART
print "Content-type:text/html\n\n";
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 28th, 2006, 12:40 PM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Try:
Perl Syntax (Toggle Plain Text)
  1. print "Status: 302 Moved\nLocation: $url";
Where $url is the URL you wish to which you wish the user to be redirected.
Arevos is offline   Reply With Quote
Old Jul 28th, 2006, 1:01 PM   #6
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3 kruptof is on a distinguished road
still gettting the same error, here is the new code:
#!/Perl/bin/perl
use CGI;
$results=new CGI;

$comment=$results->param("comments");
$name=$results->param("name");
open(DAT,">>Comments.txt");
$i=60;
$j=0;
$szlen=length $comment;
print DAT $name."<br>";
print DAT "\n";

if($szlen<60)
{
	print DAT $comment."<br>";
}
else
{
	
	while($i<=$szlen)
	{
		print DAT substr($comment,$j,$i)."<br>";
		$j=$i;
		$i+=60;
	}
	if($i<$szlen)
	{
		print DAT substr($comment,$i,$$szlen-$i)."<br>";
	}
}
close(DAT);
open(DAT,"Comments.txt");
my @cont=<DAT>;
close(DAT);
$url="/test\.html";
print "Status: 302 Moved\nLocation: $url";
print "Content-type:text/html\n\n";
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 28th, 2006, 1:30 PM   #7
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3 kruptof is on a distinguished road
after some googling and some trails and errors i have found this:
print "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>";
print "<html><head><title>$page_title</title>";
print "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=http://www.somedomain.com'>";
print "</HEAD><BODY></BODY></HTML>";

there is still some thing wrong with this html but i will post that in the html forum.......thank you everyone for the help.
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 28th, 2006, 1:50 PM   #8
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
What happens if you put the full URL in? And what happens when you go to said URL normally?
Arevos is offline   Reply With Quote
Old Jul 28th, 2006, 2:34 PM   #9
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3 kruptof is on a distinguished road
i got an error 404
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jul 28th, 2006, 2:38 PM   #10
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
In both cases? Then surely it's nothing to do with the redirect script, but because the URL you're going to does not exist.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
cgi/perl script + IE problem joyceshee Perl 2 Jan 24th, 2006 11:10 AM
libraries matko C 1 Jan 22nd, 2006 2:12 PM
Problem with Perl script eclipsed4utoo Perl 1 Dec 2nd, 2005 1:33 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC