chuckman Posted June 22, 2008 Share Posted June 22, 2008 my code: <?php session_start(); include("function.php"); ?> <html> <head> <title>idk brought to you by chuckman.org</title> </head> <body> <h1>idk</h1> <?php $comic = glob("images/*.jpg"); img($comic[$_SESSION['comic']],""); if($_SESSION['comic'] != 0) { a("back.php","Back to".$_SESSION['comic']-1); } a("forward.php","Forward to".$_SESSION['comic']+1); ?> </body> </html> img() is a function defined in "function.php" so is a() I want to know what I need to change in line 15 $comic[$_SESSION['comic']] to make it work.. because I understand that the type of the character is wrong, but I don't know how to define it as an integer.. Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/ Share on other sites More sharing options...
Stooney Posted June 22, 2008 Share Posted June 22, 2008 $comic[$_SESSION['comic']] I can't make out what is supposed to be going on here, but I'm pretty sure that's not correct syntax. Maybe this? $comic.$_SESSION['comic'] As far as converting to int, try using intval(). Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571290 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Author Share Posted June 22, 2008 The purpose of the script, is for a comic, so when people come the are at the same spot there were at.. So $_SESSION['comic'] is supposed to hold a number value and when it is in the array $comic it pulls up the right one so let's say $_SESSION['comic'] is 3 that means that code will render $comic[3] and out put that one, which will use the img() function to place it on the page. Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571297 Share on other sites More sharing options...
kenrbnsn Posted June 22, 2008 Share Posted June 22, 2008 Please post the code for the functions. Ken Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571300 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Author Share Posted June 22, 2008 It's pretty long <?php if (stristr(htmlentities($_SERVER["PHP_SELF"]), "function.php")) { Header("Location: index.php"); die(); } else { /* Name: New Line Input: nl(); Output: \n */ function nl() { echo "\n"; } /* Name: Link Input: a("http://chuckman.org ","Chuckman"); Output: <a href=\"http://chuckman.org\">Chuckman</a> */ function a($f_tar, $f_ame) { echo "<a href=\"".$f_tar."\">"; echo $f_ame; echo "</a>"; nl(); } /* Name: Div Input: div(\"main\"); Output: <div id=\"main\"> */ function div($f_id) { echo "<div id=\"".$f_id."\">"; nl(); } /* Name: End Div Input: enddiv(); Output: </div> */ function enddiv() { echo "</div>"; nl(); } /* Name: Break Input: br(3); Output: <br />\n<br />\n<br />\n */ function br($f_y) { for ($f_i=1;$f_i<=$f_y;$f_i++) { echo "<br />"; nl(); } } /* Name: Input Input: input(\"text\",\"username\", \"Username\") Output: <input type=\"text\" name=\"username\" value=\"Username\" /><br /> NOTE: Changes if you add br and size */ function input($f_type, $f_ne, $f_value, $f_br="1", $f_size="") { if (EMPTY($f_value)) { if (EMPTY($f_size)) { echo "<input name=\"$f_ne\" type=\"$f_type\" />"; } else { echo "<input name=\"$f_ne\" type=\"$f_type\" size=\"$f_size\" />"; } } elseif (EMPTY($f_size)) { echo "<input type=\"$f_type\" name=\"$f_ne\" value=\"$f_value\" />"; } else { echo "<input name=\"$f_ne\" type=\"$f_type\" size=\"$f_size\" value=\"$f_value\" />"; } br($f_br); } /* Name: Form Input: form(\"post\",\"action.php\"); Output: <form method=\"post\" action=\"action.php\"> */ function form($f_method, $f_action) { echo "<form method=\"$f_method\" action=\"$f_action\">"; nl(); } /* Name: End Form Input: endform(); Output: </form> */ function endform($f_fvalue="Submit") { echo "<input type=\"submit\" value=\"$f_fvalue\">"; nl(); echo "</form>"; nl(); } /* Name: Heading Input: h(3,\"Awesomeness\"); Output: <h3>Awesomeness</h3> */ function h($f_num, $f_text) { echo "<h".$f_num.">"; echo $f_text; echo "</h".$f_num.">"; nl(); } /* Name: Doctype Input: dtd(); Output: <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd \"> */ function dtd() { echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd \">"; nl(); } /* Name: HTML Input: html(); Output: <html xmlns=\"http://www.w3.org/1999/xhtml\"> */ function html() { echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">"; nl(); } /* Name: HTML Input: endhtml(); Output: </html> */ function endhtml() { echo "</html>"; nl(); } /* Name: Body Input: body(); Output: <body> */ function body() { echo "<body>"; nl(); } /* Name: Body Input: body(); Output: <body> */ function endbody() { echo "</body>"; nl(); } /* Name: Head Input: head(); Output: <head> */ function head() { echo "<head>"; nl(); } /* Name: End Head Input: endhead(); Output: </head> */ function endhead() { echo "</head>"; nl(); } /* Name: Title Input: title(\"Cool Whip\"); Output: <title>Cool Whip</title> */ function title($f_tname) { echo "<title>"; echo $f_tname; echo "</title>"; nl(); } /* Name: Meta Input: meta(\"Author\",\"Kaleb Mulder\"); Output: <meta name=\"Author\" content=\"Kaleb Mulder\" /> */ function meta($f_mname,$f_mcon) { echo "<meta name=\"$f_mname\" content=\"$f_mcon\" />"; nl(); } /* Name: Encoding Input: enc(); Output: <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> */ function enc() { echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"; nl(); } /* Name: Stylesheet Input: style(\"css.css\"); Output: <link rel=\"stylesheet\" type=\"text/css\" href=\"css/css.css\" /> */ function style($f_src) { echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$f_src."\" />"; nl(); } /* Name: Paragraph Input: p(); Output: <p class=\"main\"> */ function p($f_info) { echo "<p class=\"main\">"; echo $f_info; echo "</p>"; nl(); } /* Name: Unordered List Input: ul(); Output: <ul> */ function ul() { echo "<ul>"; nl(); nl(); } /* Name: End Unordered List Input: endul(); Output: </ul> */ function endul() { echo "</ul>"; nl(); } /* Name: List Item Input: li(); Output: <li> */ function li() { echo "<li>"; nl(); } /* Name: End List Item Input: endli(); Output: </li> */ function endli() { echo "</li>"; nl(); nl(); } /* Name: Font Input: f(\"u\",\"Underlined Text\"); Output: <span class=\"u\">Underlined Text</span> Note: Function CSS is required for this function */ function f($f_ftype, $f_ut) { echo "<span class=\"$f_ftype\" >"; echo $f_ut; echo "</span>"; } /* Name: Select Input: select(\"food\"); Output: <select name=\"food\"> */ function select($f_sname) { echo "<select name=\"$f_sname\">"; nl(); } /* Name: End Select Input: endselect(); Output: </select> */ function endselect() { echo "</select>"; nl(); } /* Name: Option Input: option(\"Pizza\"); Output: <option>Pizza</option> */ function option($f_val) { echo "<option>"; echo $f_val; echo "</option>"; nl(); nl(); } /* Name: Text Area Input: option(\"30\",\"40\",\"shoes\",\"This is the text that goes in the textarea\"); Output: <textarea rows=\"30\" cols=\"40\" name=\"shoes\"> This is the text that goes in the textarea </textarea> NOTE: Variable is suggested for text */ function textarea($f_row,$f_col,$f_taname,$f_dtxt) { echo "<textarea rows=\"$f_row\" cols=\"$f_col\" name=\"$f_taname\">"; nl(); echo $f_dtxt; nl(); echo "</textarea>"; br(1); } /* Name: Image Input: img("la.jpg","lalala") Output: <img src=\"lala.jpg\" alt=\"lalala\" /> */ function img($f_src,$f_alt) { echo "<img src=\"images/$f_src\" alt=\"$f_alt\" />"; br(1); } function random_color() { dechex(rand(0,hexdec(FFFFFF)), 6, "0", STR_PAD_LEFT); } } ?> Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571304 Share on other sites More sharing options...
kenrbnsn Posted June 22, 2008 Share Posted June 22, 2008 All's I want to see were the two functions, not all of them. Seeing them, I see they don't have any affect on the problem. You will have to put some debug code in to see what's in the SESSION array. Please add <?php echo '<pre>$_SESSION: ' . print_r($_SESSION,true) . '</pre>'; echo '<pre>$comic: ' . print_r($comic,true) . '</pre>'; ?> above where you're getting the error and post the results. Also, please post the exact error message you're getting. Ken Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571317 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Author Share Posted June 22, 2008 $_SESSION: Array ( [comic] => Array ( ) ) $comic: Array ( ) Warning: Illegal offset type in /home/content/c/h/u/chuckman/html/idk/index.php on line 17 Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571334 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Author Share Posted June 22, 2008 Fixed my own problem.. thanks <?php session_start(); include("function.php"); ?> <html> <head> <title>idk brought to you by chuckman.org</title> </head> <body> <h1>idk</h1> <?php if(!isset($_SESSION['comics'])) { $_SESSION['comics'] = 0; } $comic = glob("images/*.jpg"); img($comic[$_SESSION['comic']],""); if($_SESSION['comic'] != 0) { a("back.php","Back to".$_SESSION['comic']-1); } a("forward.php","Forward to".$_SESSION['comic']+1); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571339 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Author Share Posted June 22, 2008 never mind, still have the same problem. Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571343 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Author Share Posted June 22, 2008 <?php session_start(); include("function.php"); ?> <html> <head> <title>idk brought to you by chuckman.org</title> </head> <body> <h1>idk</h1> <?php if(!isset($_SESSION['comics'])) { $_SESSION['comics'] = 0; } $x = $_SESSION['comic']; $comic = glob("images/*.jpg"); img($comic[$x],""); if($_SESSION['comic'] != 0) { a("back.php","Back to".($_SESSION['comic']-1)); } a("forward.php","Forward to".($_SESSION['comic']+1)); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/111295-help-with-illegal-offset-type-error/#findComment-571344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.