PDA

Click to See Complete Forum and Search --> : header


gilgalbiblewhee
Aug 26th, 2010, 07:04 PM
Remind me what I need to add along with:
$add = $getChapter+1;
header("Location: wlc.hebrewtanakh.com.php?book=".$getBook."&chapter=".$add);
It is placed at the end of the html.

kows
Aug 26th, 2010, 07:33 PM
a proper, absolute URL would help.

header("Location: http://example.com/path/to/file.php");

gilgalbiblewhee
Aug 26th, 2010, 08:40 PM
a proper, absolute URL would help.

header("Location: http://example.com/path/to/file.php");
But it's for this reason:
http://www.vbforums.com/showthread.php?p=3872578#post3872578

kows
Aug 26th, 2010, 09:44 PM
.. I don't see the point you're trying to make. the URL you're trying to redirect to in your original post in this thread is not a valid URL. it looks like it's got a few typos in it, but if those aren't typos, and the file you're trying to redirect to is wlc.hebrewtanakh.com.php, then you should still be using an absolute URL rather than a relative one with the location header.

you're asking for help with sending a header, so I'm assuming that the problem was your header was not working. if this is not the problem, then you really should be more descriptive when making posts.

gilgalbiblewhee
Aug 26th, 2010, 10:37 PM
So this wouldn't work?
$add = $getChapter+1;
$goto = "HTTP://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?book=".$getBook."&chapter=".$add;
header("Location: ".$goto);
Otherwise I will use the redirect tag in the <head> and set a time limit.

kows
Aug 26th, 2010, 10:44 PM
echo out $goto and make sure it's a valid URL -- then, sure, it'll work. if it isn't a valid URL, then no, it won't work.

are you writing all of this code without actually running any of it to see what happens or something?

gilgalbiblewhee
Aug 26th, 2010, 10:51 PM
So this wouldn't work?
$add = $getChapter+1;
$goto = "HTTP://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?book=".$getBook."&chapter=".$add;
header("Location: ".$goto);
Otherwise I will use the redirect tag in the <head> and set a time limit.
How about something like this:
<?php
$add = $getChapter+1;
mysql_query($sql,$con);
$sql = "SELECT DISTINCT chapter FROM ".$dbTable3." WHERE book='".$getBook."' AND chapter='".$add."'";
$result = mysql_query($sql) or die(mysql_error());
//echo $sql;
while($row = mysql_fetch_array($result)){
//if chapter exists...I don't know how to put it in codes concerning exist or not
$goto = "HTTP://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?book=".$getBook."&chapter=".$row["chapter"];
//else the $getBook will be added by 1 and $getChapter will start from 1.
}
mysql_close($con);
header("Location: ".$goto);
?>

kows
Aug 27th, 2010, 01:50 AM
why would you loop through a result that supposedly would only return one record?

I don't understand your hangup here. if you want to redirect to a new page, just build an absolute URL, and then call the header() function. if you have a valid absolute URL, then it will redirect -- period. if you're not sure if the URL is correct, echo it out, and then paste it in your address bar.

gilgalbiblewhee
Aug 27th, 2010, 11:21 PM
Ok the redirecting works for a while and stops saying:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept cookies.
<?php
ob_start();
header("Content-Type: text/html; charset=utf-8");
error_reporting(E_ALL);
ini_set('display_errors', true);
set_time_limit(480);
// Database connection file
require_once("dbconnection.php");
//require_once("logininfo.php");

if($group !== "Administrator"){
//header("Location: " . $baseURL);
}

$getBook = mysql_real_escape_string($_GET["book"]);
$getChapter = mysql_real_escape_string($_GET["chapter"]);

// Create table
$sql = "CREATE TABLE IF NOT EXISTS ".$dbTable7."(
id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
book int(3),
book_title_eng mediumtext,
book_title mediumtext,
chapter int(3),
verse int(3),
text_data longtext)";

//collect the newly created fields to insert values within
mysql_query($sql,$con);
$sql = "SHOW FIELDS FROM ".$dbTable7;
$result = mysql_query($sql) or die(mysql_error());
$fields = array();
while ($row = mysql_fetch_array($result)){
$fields[]= $row['Field'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Interlinear - Page <?php echo $_GET["page"];?></title>
<style>
.hebrew{
color: green;
}
</style>
</head>

<body>
<?php
// when the page url shows no results
if($getBook=="" or $getChapter==""){
$getBook=1;
$getChapter=1;
}
//mysql_query($sql,$con);
$sql = "SELECT DISTINCT book_title FROM ".$dbTable3." WHERE book='".$getBook."' AND chapter='".$getChapter."' ORDER BY id ASC";
$result = mysql_query($sql) or die(mysql_error());
//echo $sql;

while($row = mysql_fetch_array($result)){
$book_title = $row["book_title"];
$file = file_get_contents("http://wlc.hebrewtanakh.com/".strtolower($book_title)."/".$getChapter.".htm");
preg_match_all("#<div.*>(.+)</div#Ui", $file, $innerDIV);
/***************************************************begin hebrew title chapter*******************************************************/
// between the two a tags
$replace_final_a_tag = str_replace("</a> ", "</a><li style=\"font-weight: bold;\"><span style=\"color: red;\">", $innerDIV[1][1]);
$replace_beginning_a_tag = str_replace(" <a", "</span></li><a", $replace_final_a_tag);
//search for space in span
preg_match_all("#<span.*>(.+)</span#Ui", $replace_beginning_a_tag, $space);
//print_r($space);
$book_and_title_heb = explode(" ", $space[1][0]);
$chapter=$book_and_title_heb[1];
$book_title_heb=$book_and_title_heb[0];
/***************************************************end hebrew title chapter*********************************************************/
/***************************************************begin english title chapter******************************************************/
preg_match_all("#<a.*>(.+)</a#Ui", $innerDIV[1][2], $a);
/***************************************************end english title chapter********************************************************/
// all <div>s with a style
preg_match_all('/<div style="direction:rtl">(.*)<\/div>/si', $file, $matches);
$add_span_beginning = str_replace("&nbsp;", "\n<span>", $matches[0][0]);
$add_span_end = str_replace("<span class=\"reftext\">", "</span>
<span class=\"reftext\">", $add_span_beginning);
$replace_close_span = str_replace("<div style=\"direction:rtl\"></span>", "<div style=\"direction:rtl\">", $add_span_end);
$replace_close_p = str_replace("<p></div>", "</span></div>", $replace_close_span);
$replace_open_p = str_replace("<p>
</span>
", "</span>", $replace_close_p);
$bring_up_close_span = str_replace("
</span>
", "</span>
", $replace_open_p);
preg_match_all("#<span.*>(.+)</span#Ui", $bring_up_close_span, $hebrew);
//print_r($hebrew[1]);
//The hebrew is every odd number of the array
$link = Array();
$text_data = Array();
for($i=0; $i<count($hebrew[1]); $i++){
if(($i % 2) == 0){
preg_match_all("#<b.*>(.+)</b#Ui", $hebrew[1][$i], $link[]);
}else{
$text_data[] = $hebrew[1][$i];
}
}
//print_r($text_data);
mysql_query($sql,$con);
$verse = Array();
$num=count($link)-1;

for($i=0; $i<$num; $i++){
$verse[]=$link[$i][1][0];
}

for($i=0; $i<$num; $i++){
$values = Array($id, $getBook, $book_title_heb, $book_title, $chapter, $verse[$i], $text_data[$i]);
//print_r($values);

$sql = "INSERT INTO ".$dbTable7." (";
$num2 = count($fields)-1;
for($j=0; $j<count($fields); $j++){
$sql .=$fields[$j];
if($j<$num2){
$sql .=", ";
}
}
$sql .=") VALUES ('";

$num2 = count($values)-1;
for($j=0; $j<count($values); $j++){
$sql .=$values[$j];
if($j<$num2){
$sql .="', '";
}
}
$sql .="')";
echo "<span style=\"color: red;\">".$sql."</span><br />\n";
//$result = mysql_query($sql) or die(mysql_error());
$result = mysql_query($sql);
}
} //closes the while loop
?>
<table>
<tr>
<?php
////print_r($fields);
for($th=0; $th<count($fields); $th++){
echo "<th style=\"border: 1px solid black;\">";
echo $fields[$th];
echo "</th>\n";
}
?>
<th style="border: 1px solid black;">
New Columnname:
<input type="text" name="columnname" value="" />
New Columntype:
<input type="text" name="columntype" value="" />
</th>
</tr>
<?php
mysql_query($sql2,$con);
$sql2 = "SELECT * FROM ".$dbTable7;
$result2 = mysql_query($sql2) or die(mysql_error());
//echo $sql;

while ($row2 = mysql_fetch_array($result2)){
?>
<tr>
<?php
for($td=0; $td<count($fields); $td++){
echo "<td style=\"border: 1px solid black;\">";
echo $row2[$fields[$td]];
echo "</td>\n";
}
//echo count($row);


?>
<td style="border: 1px solid black;">
</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
<?php
$addBook = $getBook+1;
$addChapter = $getChapter+1;
mysql_query($sql,$con);
$sql = "SELECT COUNT(DISTINCT chapter) as count FROM ".$dbTable3." WHERE book='".$getBook."'";
extract(mysql_fetch_assoc(mysql_query($sql)));
//echo $sql;
echo $count; //amount of verses in the chapter
if($getBook<67){
if($addChapter>$count){
$goto = "HTTP://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?book=".$addBook."&chapter=1";
}else{
$goto = "HTTP://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?book=".$getBook."&chapter=".$addChapter;
}
}
mysql_close($con);
header("Location: ".$goto);
?>
I see duplicate entries.

kows
Aug 28th, 2010, 11:38 AM
getting that error could mean that you're redirecting the page to the same page you're on, which creates an infinite loop. it looks like you're redirecting to this same script script over and over again without even an action being taken. you realize this will make it impossible to actually view any of those pages, right..?

gilgalbiblewhee
Aug 28th, 2010, 03:55 PM
getting that error could mean that you're redirecting the page to the same page you're on, which creates an infinite loop. it looks like you're redirecting to this same script script over and over again without even an action being taken. you realize this will make it impossible to actually view any of those pages, right..?

My main concern is to upload the data in the db. I did make a table to make sure everything runs smoothly. Can I set a time limit so that it can stop for 2 seconds? Will that help to avoid this problem?

kows
Aug 28th, 2010, 04:01 PM
.. no? I don't think you understand what headers do. headers tell a browser how to react to a request. if a "Location" header is sent, it will send the browser to the new location (and will not load the rest of the current page).

you do not want to be sending a header for whatever you're trying to do.

gilgalbiblewhee
Aug 28th, 2010, 04:12 PM
.. no? I don't think you understand what headers do. headers tell a browser how to react to a request. if a "Location" header is sent, it will send the browser to the new location (and will not load the rest of the current page).

you do not want to be sending a header for whatever you're trying to do.

I guess it doesn't matter if it's placed at the end of the page or the beginning?

kows
Aug 28th, 2010, 04:32 PM
no. a header does what I described. it redirects the browser to a new page. there is no delay, no timer, nothing. whatever you're trying to do is not going to be accomplished with a header.

gilgalbiblewhee
Aug 28th, 2010, 05:28 PM
no. a header does what I described. it redirects the browser to a new page. there is no delay, no timer, nothing. whatever you're trying to do is not going to be accomplished with a header.
<?php
$addBook = $getBook+1;
$addChapter = $getChapter+1;
mysql_query($sql,$con);
$sql = "SELECT COUNT(DISTINCT chapter) as count FROM ".$dbTable3." WHERE book='".$getBook."'";
extract(mysql_fetch_assoc(mysql_query($sql)));
//echo $sql;
echo $count; //amount of verses in the chapter
if($getBook<67){
if($addChapter>$count){
//$goto = "HTTP://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?book=".$addBook."&chapter=1";
//$goto = $_SERVER['PHP_SELF']."?book=".$addBook."&chapter=1";
$goto = "wlc.hebrewtanakh.com.php?book=".$addBook."&chapter=1";
?>
<meta http-equiv="Refresh" content="5;url=<?php echo $goto; ?>" >
<?php
}else{
//$goto = "HTTP://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?book=".$getBook."&chapter=".$addChapter;
//$goto = $_SERVER['PHP_SELF']."?book=".$getBook."&chapter=".$addChapter;
$goto = "wlc.hebrewtanakh.com.php?book=".$getBook."&chapter=".$addChapter;
?>
<meta http-equiv="Refresh" content="5;url=<?php echo $goto; ?>" >
<?php
}
}
?>