Page 1 of 2

Header Location Issue

Posted: Wed Mar 02, 2005 12:27 am
by s.dot
I have this code... in which the header: location line is not working. It's the last line of the code, all of the rest of the code may be irrelevant, but I posted it just in case.

Code: Select all

if($action == "postreply"){
if(!isset($_COOKIEї'username'])) { echo "You must be logged in to post in the forums."; require 'forumsfooter.php'; die(); }
if(!entry) { echo "You cannot submit an empty reply"; require 'forumsfooter.php'; die(); }
$time2 = time();
$forumsql = "SELECT id, topicname, forumid FROM forumtopicmain WHERE id = '$threadid'";
$forumquery = mysql_query($forumsql);
$forumarray = mysql_fetch_array($forumquery);
$forumnamesql = "SELECT id FROM forumtopics WHERE id = '".$forumarrayї'forumid']."'";
$forumnamequery = mysql_query($forumnamesql);
$forumnamearray = mysql_fetch_array($forumnamequery);
$forumaid = $forumnamearrayї'id'];
$date = date("M d");
$date2 = date("g:i A");
$date3 = "$date at $date2";
$smilies = array("::arrow::", "::badgrin::", "::biggrin::", "::confused::", "::cool::", "::cry::", "::doubt::", "::evil::", "::exclaim::", "::idea::", "::lol::", "::mad::", "::neutral::", "::question::", "::razz::", "::redface::", "::rolleyes::", "::sad::", "::shock::", "::smile::", "::surprised::", "::wink::");
$smiliesimg = array("<img src=smilies/arrow.gif>", "<img src=smilies/badgrin.gif>", "<img src=smilies/biggrin.gif>", "<img src=smilies/confused.gif>", "<img src=smilies/cool.gif>", "<img src=smilies/cry.gif>", "<img src=smilies/doubt.gif>", "<img src=smilies/evil.gif>", "<img src=smilies/exclaim.gif>", "<img src=smilies/idea.gif>", "<img src=smilies/lol.gif>", "<img src=smilies/mad.gif>", "<img src=smilies/neutral.gif>", "<img src=smilies/question.gif>", "<img src=smilies/razz.gif>", "<img src=smilies/redface.gif>", "<img src=smilies/rolleyes.gif>", "<img src=smilies/sad.gif>", "<img src=smilies/shock.gif>", "<img src=smilies/smile.gif>", "<img src=smilies/surprised.gif>", "<img src=smilies/wink.gif>");

		// Linking function //

function make_clickable($text) 
&#123; 

   $ret = ' ' . $text; 
   $ret = preg_replace("#(^|&#1111;\n ])(&#1111;\w]+?://&#1111;^ "\n\r\t<]*)#is", "\\1<a href="\\2" target="_blank">\\2</a>", $ret); 
   $ret = preg_replace("#(^|&#1111;\n ])((www|ftp)\.&#1111;^ "\t\n\r<]*)#is", "\\1<a href="http://\\2" target="_blank">\\2</a>", $ret); 
   $ret = preg_replace("#(^|&#1111;\n ])(&#1111;a-z0-9&\-_.]+?)@(&#1111;\w\-]+\.(&#1111;\w\-\.]+\.)*&#1111;\w]+)#i", "\\1<a href="mailto:\\2@\\3">\\2@\\3</a>", $ret); 
   $ret = substr($ret, 1); 
   return($ret); 
&#125;

$entry2 = str_replace($smilies, $smiliesimg, $entry);
$entry3 = str_replace("&#1111;IMG]", "<img src=", $entry2);
$entry4 = str_replace("&#1111;/IMG]", ">", $entry3);
$entry5 = str_replace("&#1111;QUOTE]", "<blockquote class=code>", $entry4);
$entry6 = str_replace("&#1111;/QUOTE]", "</blockquote>", $entry5);
$entry7 = mysql_real_escape_string(nl2br(make_clickable(strip_tags($entry6, '<img>,<blockquote>'))));

$insertreplysql = "INSERT INTO forumentries (entry, time, topicid, forumid, istopic, author, time2) VALUES ('$entry7', '$date3', '$threadid', '$forumaid', 'n', '".$_COOKIE&#1111;'username']."', '$time2')";
mysql_query($insertreplysql);
$forumsql = "SELECT topicname, forumid FROM forumtopicmain WHERE id = '$threadid'";
$forumquery = mysql_query($forumsql);
$forumarray = mysql_fetch_array($forumquery);
$inserttimereply = "UPDATE `forumtopicmain` SET `lastreply` = '$time2' WHERE id = '$threadid'";
mysql_query($inserttimereply) or die(mysql_error());
header("Location: showthread.php?threadid=$threadid&page=$page");
The header variables are set in the URL. And PHP doesn't throw any errors out on me, I just end up with a blank page.

Posted: Wed Mar 02, 2005 3:03 am
by anjanesh
showthread.php?threadid=$threadid&page=$page
In showthread.php

Code: Select all

echo $_GET&#1111;'threadid'];
echo '<br>';
echo $_GET&#1111;'page'];
What is it showing ?

Posted: Wed Mar 02, 2005 9:35 am
by feyd
it appears $threadid and $page are not set anywhere.. are register_globals on?

Posted: Wed Mar 02, 2005 2:14 pm
by s.dot
They are passed from the form action and are in the URL of the page... for example http://www.domain.com/showthread.php?threadid=87&page=3

Register globals are on.

Posted: Wed Mar 02, 2005 2:19 pm
by smpdawg
Can you add this to the beginning of the script right after <?php

Code: Select all

error_reporting(E_ALL);
With that in place... When you run your script what do you see? Any kind of message from the browser? A completely blank screen?

Posted: Wed Mar 02, 2005 2:34 pm
by s.dot
No errors, just a blank page

Posted: Wed Mar 02, 2005 2:36 pm
by smpdawg
What happens is you add an echo after the header statement? Do you see that text?

Code: Select all

echo "Made it here";

Posted: Wed Mar 02, 2005 2:41 pm
by s.dot
Anything I add after the header("Location: page"); still works, I currently have a link so the users can click on to go to their forum post.

But if the header location was working correctly, it would appear seamless to the user.

Posted: Wed Mar 02, 2005 2:45 pm
by smpdawg
When there is a blank page, what do you see if you do a view source? If there is anything at all in the view source, put it here so I can see it.

Are you just trying to redirect the user after a post? If so, have you conisidered using META REFRESH instead of location?

Posted: Wed Mar 02, 2005 2:59 pm
by s.dot
Okay, I figured it out. I head it showing a body background color, which was preventing the header from being executed

but why didn't it throw out an error at me?

Posted: Wed Mar 02, 2005 3:03 pm
by smpdawg
It was up to the browser to honor that request. PHP was working fine, the browser ignored it because it had already received content. Glad to hear that it works.

Posted: Wed Mar 02, 2005 3:08 pm
by s.dot
thanks for your help :)

Posted: Wed Mar 02, 2005 3:15 pm
by s.dot
will the PHP header location always work, or should I provide a backup link just in case?

Posted: Wed Mar 02, 2005 3:24 pm
by feyd
a properly compliant browser to http standards will always work.. however, relative URL's in a Location header are only supported in newer browsers as this is a relatively recent addition to the standards. For safety, always use a fully qualified URL.

Posted: Wed Mar 02, 2005 3:25 pm
by smpdawg
You could try displaying the link after you do the location as a fallback. I haven't tried it but it is a good theory. :)

This site displays an intermediate page and does a meta refresh instead of location and it works pretty well.