• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved [PHP] Session & Cookie.

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Reaction score
72
Location
Poland
How could i make that

PHP:
$_GET['editcharacter']

PHP:
  <form action="index.php" method="">
  <nobr><input name="editcharacter" type="text" class="search" id="search" value="Search Character" size="30" maxlength="50" /> <button type="submit">Search</button></nobr>
  </form>

Would be like a cookie. That i could go through the admin panel and have the character name always set till i change it or reset it.

I hope you get my point.
 
Last edited:
Code:
<?PHP
	if($_GET['editcharacter']) setcookie('name', $_GET['editcharacter']);

	echo '<input type="text" value="{$_COOKIE['name']}" />';
?>

Code:
<?PHP
	session_start();

	if($_GET['editcharacter']) $_SESSION['name'] = $_GET['editcharacter'];

	echo '<input type="text" value="{$_SESSION['name']}" />';
?>
 
Last edited:
Core.php

Line 3 :
PHP:
 if($_GET['editcharacter']) setcookie('name', $_GET['editcharacter']);

Index.php

HTML:
<div id="searchbox">
  <label>
  <form action="index.php" method="">
  <nobr><input name="editcharacter" type="text" class="search" id="search" value="<?PHP $_SESSION['name'] ?>" size="30" maxlength="50" /> <button type="submit">Search</button></nobr>
  </form>
  </label>
  
</div>

And it dont work and send errors

Code:
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Adminpanel\index.php:5) in <b>C:\xampp\htdocs\Adminpanel\core.php</b> on line <b>3</b>

Index.php 5-37

PHP:
<?PHP
#################################################################################
##                            CONFIGURATION PAGE                               ##
#################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                  #
## ---------------------------------------------------------------------------- #
## Script created by  Kavvson (http://otland.net/members/kavvson/)              #
## Author & developer:  Kavvson                                                 #
##                                                                              #
## Helpers:             Archez       <http://www.otland.net>                    #
##                      PineIt       <http://www.otland.net>                    #
##                      Xampy        <http://www.otland.net>                    #
##                      Chojrak      <http://www.otland.net>                    #
#################################################################################
## +--------------------------Admin Panel Features------------------------------+
## | DONE: v.1
## | - Equipment Shower : Display items images
## | - Shows importat database fields : Ability to input new values and save
## | - Import list of players assigned with the account - display some info
## | 
## | TODO: v.2
## | - IDEAS
## | - Secure part ( login / password ) - admin - stored in DB
## | 
## | 
## | IDEAS:
## | - Onclick image -> popup window that contains image items. After
## |   clicking the image it will save and will be updated to the DB
## | - Health bar / Mana bar                                                
## +----------------------------------------------------------------------------+
#################################################################################
INCLUDE ('core.php'); 
?>
 
Why first you use cookie, then read data from session? :p
Code:
<div id="searchbox">
  <label>
  <form action="index.php" method="">
  <nobr><input name="editcharacter" type="text" class="search" id="search" value="<?PHP echo $_COOKIE['name']; ?>" size="30" maxlength="50" /> <button type="submit">Search</button></nobr>
  </form>
  </label>
  
</div>
 
Why first you use cookie, then read data from session? :p
Code:
<div id="searchbox">
  <label>
  <form action="index.php" method="">
  <nobr><input name="editcharacter" type="text" class="search" id="search" value="<?PHP echo $_COOKIE['name']; ?>" size="30" maxlength="50" /> <button type="submit">Search</button></nobr>
  </form>
  </label>
  
</div>

Still dont show the value or work
make sure there are no spaces at the top of those files.

There are no spaces
 
Full files

Index.php

HTML:
<!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>
<?PHP
#################################################################################
##                            CONFIGURATION PAGE                               ##
#################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                  #
## ---------------------------------------------------------------------------- #
## Script created by  Kavvson (http://otland.net/members/kavvson/)              #
## Author & developer:  Kavvson                                                 #
##                                                                              #
## Helpers:             Archez       <http://www.otland.net>                    #
##                      PineIt       <http://www.otland.net>                    #
##                      Xampy        <http://www.otland.net>                    #
##                      Chojrak      <http://www.otland.net>                    #
#################################################################################
## +--------------------------Admin Panel Features------------------------------+
## | DONE: v.1
## | - Equipment Shower : Display items images
## | - Shows importat database fields : Ability to input new values and save
## | - Import list of players assigned with the account - display some info
## | 
## | TODO: v.2
## | - IDEAS
## | - Secure part ( login / password ) - admin - stored in DB
## | 
## | 
## | IDEAS:
## | - Onclick image -> popup window that contains image items. After
## |   clicking the image it will save and will be updated to the DB
## | - Health bar / Mana bar                                                
## +----------------------------------------------------------------------------+
#################################################################################
INCLUDE ('core.php'); 
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?PHP echo $config['site']['name']; ?></title>

<!--// SCRIPTS FOR DROPDOWN AND TABBED INTERFACE -->

<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/dropmenu.js" type="text/javascript"></script>

<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-personalized-1.5.2.packed.js"></script>
<script type="text/javascript" src="js/sprinkle.js"></script>

<!--// FOLLOWING SCRIPT IS FOR PNG FIX IE5.5/IE6-->
    

<!--[if lt IE 7]>
<script defer type="text/javascript" src="js/pngfix.js"></script> 
<![endif]--> 

<link href="css/styles.css" rel="stylesheet" type="text/css" />

</head>
<body>

<!--// Horisontal submenu edit starts -->

<div class="bodytext" id="submenu"> 
  <table width="493" border="0" class="class2">
    <tr>
      <td valign="middle"><a href="table.html">Characters</a></td>
      <td valign="middle"><a href="login.html">News Editor</a></td>
      <td valign="middle"><a href="#">Character Preview</a></td>
    </tr>
  </table>
</div>

<!--// Horisontal submenu edit ends -->
<!--// Logo edit starts -->

<div id="logo">
  <div align="center"><br />
    <img src="http://otland.net/images/logo.png" alt="logo" width="116" height="34" /><br />
  </div>
</div>

<!--// logo edit ends -->
<!--// Arrows edit starts -->

<div id="arrows"></div>
<div class="bodytext" id="hello">Hello <a href="#">Administrator</a>, <img src="http://otland.net/images/icons/user.png" alt="user_icon" width="22" height="25" border="0" /><br />
</div>

<!--// arrows edit ends -->
<!--// Visit site starts -->

<div id="visitsite">
  <div align="center" class="toplinks">
    <div id="visitsite_icon"><a href="#"><img src="http://otland.net/images/icons/big_visitsite.png" alt="big_visitsite" width="30" height="25" border="0" /></a></div>
    <br />
    <br />
      <a href="#"><span class="toplinks">VISIT SITE</span></a></div>
</div>

<!--// Visit site edit ends -->
<!--// Users edit starts -->


<div id="users">
  <div align="center">
    <div id="users_icon"><a href="#"><img src="http://otland.net/images/icons/big_users.png" alt="big_users" width="24" height="26" border="0" /></a></div>
<span class="toplinks"><br />
      <br />
      <a href="#"><span class="toplinks">USERS</span></a></span></div>
  <br />
</div>

<!--// users edit ends -->
<!--// Settings edit starts -->


<div id="settings">
  <div align="center">
    <div id="settings_icon"><a href="#"><img src="http://otland.net/images/icons/big_settings.png" alt="big_settings" width="25" height="26" border="0" /></a></div>
            <span class="toplinks"><br />
      <br />
      <a href="#"><span class="toplinks">SETTINGS</span></a></span><br />
  </div>
</div>

<!--// settings edit ends -->
<!--// Logout edit starts -->

<div id="logout">
  <div align="center">
    <div id="logout_icon"><a href="#"><img src="http://otland.net/images/icons/big_logout.png" alt="big_logout" width="25" height="25" border="0" /></a></div>
<span class="toplinks"><br />
      <br />
      <a href="#"><span class="toplinks">LOG OUT</span></a></span><br />
  </div>
</div>

<!--// logout edit ends -->
<!--// Dropdown edit starts -->




<!--// dropdown edit ends -->
<!--// leftcolumn edit starts -->
    <!--// Mainnavigation edit starts -->


<div id="leftcolumn">
  <div id="navigation"><img src="http://otland.net/images/title_bg.png" alt="titlebg" width="180" height="49" />
    <div class="toplinks style1" id="navigationtitle"><strong>Main navigation</strong><br /> <!--// Title -->
      <br />
      <table width="158" border="0">
        <tr>
          <td width="18" align="center"><img src="http://otland.net/images/icons/dashboard.png" alt="dashboard" width="16" height="13" /></td>
          <td width="130" class="navigation"><a href="#">Dashboard</a></td> <!--// Dashboard -->
        </tr>
        <tr>
          <td align="center"><img src="http://otland.net/images/icons/articles.png" alt="articles" width="16" height="13" /></td>
          <td class="navigation"><a href="?page=showcharacter&editcharacter=<?PHP echo $_GET['editcharacter']; ?>">Chatacter</a></td> <!--// Articles -->
        </tr>
        <tr>
          <td align="center"><img src="http://otland.net/images/icons/gallery.png" alt="galleries" width="18" height="12" /></td>
          <td class="navigation"><a href="#">Galleries</a></td> <!--// Galleries -->
        </tr>
        <tr>
          <td align="center"><img src="http://otland.net/images/icons/calendar.png" alt="calendar" width="15" height="15" /></td>
          <td class="navigation"><a href="#">Calendar</a></td> <!--// Calendar -->
        </tr>
        <tr>
          <td align="center"><img src="http://otland.net/images/icons/users.png" alt="users" width="16" height="18" /></td>
          <td class="navigation"><a href="#">Users</a></td> <!--// Users -->
        </tr>
        <tr>
          <td align="center"><img src="http://otland.net/images/icons/statistics.png" alt="statistics" width="14" height="16" /></td>
          <td class="navigation"><a href="#">Statistics</a></td> <!--// Statistics -->
        </tr>
        <tr>
          <td align="center"><img src="http://otland.net/images/icons/settings.png" alt="settings" width="14" height="14" /></td>
          <td class="navigation"><a href="#">Settings</a></td> <!--// Settings -->
        </tr>
        <tr>
          <td align="center"><img src="http://otland.net/images/icons/support.png" alt="support" width="16" height="16" /></td>
          <td class="navigation"><a href="3.html">Help &amp; Support</a></td> <!--// Support -->
        </tr>
      </table>
      <br />
    </div>
  </div>
  
    <!--// leftcolumn edit ends -->
  
  <img src="http://otland.net/images/navi_bg.jpg" alt="navi_bg" width="225" height="323" /><img src="http://otland.net/images/navi_bg.jpg" alt="navi_bg" width="225" height="323" /><br />
  
      <!--// articles edit starts -->
  
  <div id="latest"><img src="http://otland.net/images/title_bg.png" alt="titlebg" width="180" height="49" />
    <div class="toplinks style1" id="latestitle"><strong>Data Grids<br /> <!--// Title -->
      <br />
    </strong>
    
    
      <table>
        <tr>
          <td align="center"><a href="#"><img src="http://otland.net/images/icons/add.png" alt="add" width="18" height="17" border="0" /></a></td>
          <td class="navigation"><a href="#">Add Article</a></td> <!--// Add article -->
        </tr>
          <tr>
            <td width="18" align="center"><a href="#"><img src="http://otland.net/images/icons/edit.png" alt="edit" width="18" height="18" border="0" /></a></td>
            <td width="130" class="navigation"><a href="#">Characters</a></td> <!--// Article #1... -->
        </tr>
          <tr>
            <td align="center"><a href="#"><img src="http://otland.net/images/icons/edit.png" alt="edit" width="18" height="18" border="0" /></a></td>
            <td class="navigation"><a href="#">News</a></td>
        </tr>
          <tr>
            <td align="center"><a href="#"><img src="http://otland.net/images/icons/edit.png" alt="edit" width="18" height="18" border="0" /></a></td>
            <td class="navigation"><a href="#">Artictle Title #3</a></td>
          </tr>
          <tr>
            <td align="center"><a href="#"><img src="http://otland.net/images/icons/edit.png" alt="edit" width="18" height="18" border="0" /></a></td>
            <td class="navigation"><a href="#">Artictle Title #4</a></td>
          </tr>
          <tr>
            <td align="center"><a href="#"><img src="http://otland.net/images/icons/edit.png" alt="edit" width="18" height="18" border="0" /></a></td>
            <td class="navigation"><a href="#">Artictle Title #5</a></td>
          </tr>
          <tr>
            <td align="center"><a href="#"><img src="http://otland.net/images/icons/edit.png" alt="edit" width="18" height="18" border="0" /></a></td>
            <td class="navigation"><a href="#">Artictle Title #6</a></td>
          </tr>
          <tr>
            <td align="center"><a href="#"><img src="http://otland.net/images/icons/edit.png" alt="edit" width="18" height="18" border="0" /></a></td>
            <td class="navigation"><a href="#">Artictle Title #7</a></td> <!--// ...Article #7 -->
          </tr>
        </table>
      <br />
    </div>
  </div>
  
    <!--// articles edit ends -->
    <!--// Calendar starts -->
  <img src="http://otland.net/images/navi_bg.jpg" alt="navi_bg" width="225" height="323" /><br />
    


<div id="tabvanilla" class="widget">

            <ul class="tabnav">
                <li class="class2"><span class="bodytext"><a href="#popular">Sidebar links</a></span></li> <!--// SIDEBAR LINKS TITLE -->
              <li class="class2"><span class="bodytext"><a href="#recent">top tips</a></span></li><!--// TOPTIPS TITLE -->
    </ul>
            <!--/sidebar links-->
            <div id="popular" class="tabdiv"><span class="bodytext"><strong>SIDEBAR LINKS</strong><br />
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin bibendum nisi at ipsum. Nam sodales neque et urna. Nunc ultricies. Maecenas ipsum. Ut suscipit. 
          Sed posuere feugiat metus. Duis at turpis non nulla adipiscing viverra.</span></div>
            
<span class="bodytext">
            <!--/toptips-->
            </span>
            <div id="recent" class="tabdiv">
                <p><span class="bodytext"><strong>TOP TIPS</strong><br />
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin bibendum nisi at ipsum. Nam sodales neque et urna. Nunc ultricies. Maecenas ipsum. Ut suscipit. 
            Sed posuere feugiat metus. Duis at turpis non nulla adipiscing viverra.</span><br />
              <br />
              <span class="bodytext">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin bibendum nisi at ipsum. Nam sodales neque et urna. Nunc ultricies. Maecenas ipsum. Ut suscipit. 
              Sed posuere feugiat metus. Duis at turpis non nulla adipiscing viverra.</span></p>
    </div>
            <span class="bodytext">
            </span>
  </div>
 
</div>


<link href="z_auto/css/smoothness/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="z_auto/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="z_auto/js/jquery-ui-1.8.custom.min.js"></script>        

<script type="text/javascript">
    $(function(){
        //attach autocomplete
        $("#search").autocomplete({
            //define callback search format results
            source: function(req, add){
                //pass request search server
                $.getJSON("/show.php?characters=?", req, function(data) {
                    //create array for response objects
                    var suggestions = [];
                    //process response
                    $.each(data, function(i, val){                                
                        suggestions.push(val.name);
                    });
                    //pass array search callback
                    add(suggestions);
                });
            }
        });
    });
    
    function fill(thisValue) {
        $('#search').val(thisValue);
    }
</script>


<!--// Content starts -->
<div id="searchbox">
  <label>
  <form action="index.php" method="">
  <nobr><input name="editcharacter" type="text" class="search" id="search" value="<?PHP echo $_COOKIE['name']; ?>" size="30" maxlength="50" /> <button type="submit">Search</button></nobr>
  </form>
  </label>
</div>


<div id="content"> 

<?php
$page = ((isset($_GET['page']) && $_GET['page'] != '') ? $_GET['page'] : 'home');
$page=(preg_match('/(\.\.|\/)/i',$page)?'home':$page);
$page = preg_replace('/[^a-zA-Z0-9 \._-]/','',$page);
$page = (file_exists('./pages/'.$page.'.php') ? $page : 'error');
include('./pages/'.$page.'.php');
?>
  
 </div>  
 





<!--// Searchbox ends -->


</body>


</html>

Core.php

HTML:
<?PHP if($_GET['editcharacter']) setcookie('name', $_GET['editcharacter']);
#################################################################################
##                            CONFIGURATION PAGE                               ##
#################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                  #
## ---------------------------------------------------------------------------- #
## Script created by  Kavvson (http://otland.net/members/kavvson/)              #
## Author & developer:  Kavvson                                                 #
##                                                                              #
## Helpers:             Archez       <http://www.otland.net>                    #
##                      PineIt       <http://www.otland.net>                    #
##                      Xampy        <http://www.otland.net>                    #
#################################################################################
## +--------------------------Admin Panel Features------------------------------+
## | DONE: v.1
## | - Equipment Shower : Display items images
## | - Shows importat database fields : Ability to input new values and save
## | - Import list of players assigned with the account - display some info
## | 
## | TODO: v.2
## | - IDEAS
## | - Secure part ( login / password ) - admin - stored in DB
## | 
## | 
## | IDEAS:
## | - Onclick image -> popup window that contains image items. After
## |   clicking the image it will save and will be updated to the DB
## | - Health bar / Mana bar                                                
## +----------------------------------------------------------------------------+
#################################################################################

#################################################################################
## +---------------------------------------------------------------------------
## | Database Connection
## +---------------------------------------------------------------------------
#################################################################################
        
    $mysqli = new mysqli( 
    'localhost', // Host
    'root', // User
    '', // Password
    'test' // Database name
    );
    
   if (!$mysqli) { die('<img src="http://otland.net/images/leave-icon.png" style="width: 19px" "> Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());}    
   //echo '<div align="right"><img src="http://otland.net/images/ok.png" style="width: 19px" "> DB : ' . mysqli_get_host_info($mysqli) . "</div>";    

#################################################################################
## +---------------------------------------------------------------------------
## | Windows configuration 
## +---------------------------------------------------------------------------
## $window_decor = "mac_os_x" - theme name
## $window_title = "title" - You can define here the window title. You can use html tags. Like fe. <B>
## $window_width  = "100" - Define the width of the window. You can only input a value. You cannot use the type of width = px,%,cm,mm etc.
## $window_height = "100" - Define the height of the window. You can only input a value. You cannot use the type of height = px,%,cm,mm etc.
## $window_content = "file.php" - Define here the content of the window. You can use a url: http://google.com ; you can also read files from .php .html .txt etc.
#################################################################################


$window_decor = "mac_os_x"; // The theme to load for the window system.  Added in 2.7.  Updated in 2.708
$window_title = "Czesc";


$window_title_image = "x.jpg";
$window_content = "t.txt"; //
$window_width = "333"; //
$window_height = "333"; //

#################################################################################
## +---------------------------------------------------------------------------
## | Style configuration (CSS) 
## +---------------------------------------------------------------------------
## If you want add a new stylsheet add in the array '' => '', . And the last array cant contain ,
## Write 'Name of style can be any' => 'directory.extention',
## The 'Name of style can be any' can be the same with an other. Just add a 1 or _1
## You might get some values from $test
## Only .css extentions will work
#################################################################################
 $css = array(
     'Main Style' => 'style.css',
     'Jquery Style' => 'css/jquery-ui-1.8.5.custom.css',
     'Jquery' => 'panelfiles/lib/jquery.tooltip.css',
     'Windows Style' => 'windowsjs/themes/default.css',
     '' => '',
     'Window Style1' => 'z_window/windowsjs/themes/'.$window_decor.'.css'
             );
             /* Make it working dont change until u have to */
        foreach($css as $key => $value){ echo '<link rel="stylesheet" href="'.$value.'" />';}
        
#################################################################################
## +---------------------------------------------------------------------------
## | Script configuration (JS) 
## +---------------------------------------------------------------------------
## If you want add a new javascript add in the array '' => '', . And the last array cant contain ,
## Write 'Name of style can be any' => 'directory.extention',
## The 'Name of style can be any' can be the same with an other. Just add a 1 or _1
## You might get some values from $test
## Only .js extentions will work
#################################################################################

 $js = array(
     'Jquery' => 'panelfiles/lib/jquery.js',
     'Jquery1' => 'js/jquery-1.4.2.min.js',
     'JS' => 'panelfiles/lib/jquery.dimensions.js',
     'TT' => 'panelfiles/lib/jquery.tooltip.js',
     'Window' => 'z_window/prototype/prototype.js',
     'Window1' => 'z_window/windowsjs/javascripts/effects.js',
     'Window2' => 'z_window/windowsjs/javascripts/window.js',
     'Window3' => 'z_window/windowsjs/javascripts/window_effects.js'
             );
             /* Make it working dont change until u have to */
       foreach($js as $key => $value) {echo '<script src="'.$value.'" type="text/javascript"></script>';}


   
   
#################################################################################
## +---------------------------------------------------------------------------
## | Database queries
## +---------------------------------------------------------------------------
#################################################################################

    $result = $mysqli->query( 'SELECT * FROM `players` WHERE `name` = \''.$mysqli->real_escape_string( $_GET['editcharacter'] ).'\' LIMIT 1;' )->fetch_assoc( );
    $accountresult = $mysqli->query( 'SELECT * FROM `players` LEFT JOIN `accounts` ON `accounts`.`id` = `players`.`account_id` WHERE `players`.`name` = \''.$mysqli->real_escape_string( $_GET['editcharacter'] ).'\';' )->fetch_assoc( );  

?>
 
Last edited:
And what if you put setcookie in index.php? :p

Also change
PHP:
 to [CODE], will take less time to scroll page :p.
 
That error can occur when you call session_start(); twice I think. It's a weird error, I've had it a few times.

EDIT: Once I removed spaces from the top of all my files I had, it started working again lol (that was one time I got that error)
 
Last edited:
Back
Top