-
Posts
23 -
Joined
-
Last visited
Profile Information
-
Gender
Male
Ifaiden's Achievements
Newbie (1/5)
0
Reputation
-
From the link: "session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0.". It doesn't state anything about "session stays active even after the browser has been closed"
-
Ok, thanks for the quick answer. If I don't want to use cookies, can I instead place the file temporarily in a database (mysql?) and have like a timeout that removes and updates the database? Is this more optimized than cookies?
-
Yes, I am. Is this the wrong way to use it? (correction: how do I make it work? )
-
Hi! I'm working on a simple e-commerce script. I have some $_SESSION variables that is defined and works fine while surfing on the site. But when I close the browser and reenter the site, all the session-variables are not defined (unset?), until i click on a link on the site. Weird behavior... please help! /I
-
Solved this with: if(detect_ie()){ // Converts the input to UTF-8 $q=utf8_encode($q); } $q is the input string. And detect_ie checks if it's IE.
-
I identified the problem and it seems that the string you type in the input field is in ISO-8859-1. I tested to type in: "Mangold SG Hävstångscertifikat Sverige Select - (5 år)" and got a hit. This problem only occurs in Internet Explorer.
-
I don't know if this is a specific ajax problem or if it's just Internet Explorer. I'm working on an ajax live search function ( i followed the guide here http://www.w3schools.com/php/php_ajax_livesearch.asp). I'm converting an excel-file to XML. When I fill in the form with the letters å, ä, ö (Swedish) in internet explorer I get no hits. In any other browsers it works fine. I have defined UTF-8 in all the browsers, tested ISO-8859-1 (recommended Swedish) and even tried combining them. Nothing works... Any ideas? Example: http://mindu.mine.nu/amazing_solutions/XLStoXML/search.html XML-file: http://mindu.mine.nu/amazing_solutions/XLStoXML/Varderingar.xml XLS To XML <?php header('Content-Type: text/html; charset=UTF-8'); require_once('/var/www/amazing_solutions/XLStoXML/reader.php'); $data = new Spreadsheet_Excel_Reader(); $data->setUTFEncoder('iconv'); $data->setOutputEncoding('CP-1251'); // Read in excel file $data->read('/var/www/amazing_solutions/XLStoXML/Varderingar.xls'); //Count XLS-data rows // Get first sheet $sheet = $data->sheets[0]; // Get all rows in the sheet $rows = $sheet['cells']; // Find total number of rows $rowCount = count($rows); /* // Show data from last row echo "<table><tr>"; foreach($rows[$rowCount -1] as $col) { echo "<td>$col</td>"; } echo "</tr></table>"; */ //Skips the two first rows (Data begins at row 3) $rowCount=$rowCount-2; echo "Antalet rader data i excel-filen (Data börjar i rad 3): ".$rowCount.""; // End of count XLS-data rows $myFile = "Varderingar.xml"; $fh = fopen($myFile, 'w') or die("$myFile gick inte att hitta"); $stringData = "<?xml version='1.0' encoding='ISO-8859-1'?>\n<pages>\n"; fwrite($fh, $stringData); //Import XLS-data to XML-file in right format $loop_count = 0; //Data begins in row 3 $row_start_count = 3; $search = array('&'); $replace = array('&'); //title = Kolumn A, URL = ISIN.htm while($loop_count!=$rowCount){ $stringData = "<link>\n<namn>".str_replace($search, $replace, $data->sheets[0]['cells'][$row_start_count][1])."</namn>\n<url>".$data->sheets[0]['cells'][$row_start_count][5].".htm</url>\n"; fwrite($fh, $stringData); $stringData = "<dagskurs>".$data->sheets[0]['cells'][$row_start_count][2]."</dagskurs>\n"; fwrite($fh, $stringData); $stringData = "<langsiktigtvarde>".$data->sheets[0]['cells'][$row_start_count][3]."</langsiktigtvarde>\n"; fwrite($fh, $stringData); $stringData = "<index>".$data->sheets[0]['cells'][$row_start_count][4]."</index>\n"; fwrite($fh, $stringData); $stringData = "<isin>".$data->sheets[0]['cells'][$row_start_count][5]."</isin></link>\n"; fwrite($fh, $stringData); $loop_count++; $row_start_count++; } // End of import XLS-data to XML-file $stringData = "</pages>"; fwrite($fh, $stringData); fclose($fh); ?> Livesearch.php <?php header('Content-Type: text/html; charset=UTF-8'); $xmlDoc=new DOMDocument(); $xmlDoc->load("Varderingar.xml"); $x=$xmlDoc->getElementsByTagName('link'); //get the q parameter from URL $q=$_GET["q"]; //lookup all links from the xml file if length of q>0 if (strlen($q)>0) { $hint=""; for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('namn'); $z=$x->item($i)->getElementsByTagName('url'); $t=$x->item($i)->getElementsByTagName('isin'); $a=$x->item($i)->getElementsByTagName('dagskurs'); $b=$x->item($i)->getElementsByTagName('langsiktigtvarde'); $c=$x->item($i)->getElementsByTagName('index'); if ($y->item(0)->nodeType==1 && $t->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q) || stristr($t->item(0)->childNodes->item(0)->nodeValue,$q) ) { if ($hint=="") { $hint= "<table border='0' width='850' cellspacing='0' cellpadding='5px'> <tr id='headertable'> <td width='350px'> <b><font size='2'>Produkt </font></b> </td> <td width='95px'> <b><font size='2'>Isinkod </font></b> </td> <td width='105px'> <b><font size='2'>Indiaktivt Marknadsvärde </font></b> </td> <td width='78px'> <b><font size='2'>Långsiktigt Värde </font></b> </td> <td width='90px'> <b><font size='2'>Underliggande Index </font></b> </td> </tr> </table><table border='0' width='850' cellspacing='0' cellpadding='5px'><tr class='tablestyle'> <td width='350px'> <a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a><td width='95px'>" . $t->item(0)->childNodes->item(0)->nodeValue . "</td><td width='105px'>" . $a->item(0)->childNodes->item(0)->nodeValue . "</td><td width='78px'>" . $b->item(0)->childNodes->item(0)->nodeValue . "</td><td width='90px'>" . $c->item(0)->childNodes->item(0)->nodeValue . "</td></tr> </table>"; } else { $hint=$hint . "<table border='0' width='850' cellspacing='0' cellpadding='5px'><tr class='tablestyle'><td width='350px'><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a><td width='95px'>" . $t->item(0)->childNodes->item(0)->nodeValue . "</td><td width='105px'>" . $a->item(0)->childNodes->item(0)->nodeValue . "</td><td width='78px'>" . $b->item(0)->childNodes->item(0)->nodeValue . "</td><td width='90px'>" . $c->item(0)->childNodes->item(0)->nodeValue . "</td> </tr> </table>"; } } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint=="") { $response="Inga träffar"; } else { $response=$hint; } //output the response echo $response; ?> search.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> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>LiveSearchTest</title> <style type="text/css"> #livesearch{ width: 850px; padding-left: 10px; padding-top: 5px; } #livesearch a:link, #livesearch a:visited, #livesearch a:focus{ text-decoration: none; outline: none; color: #808080; font-family: arial; font-size: 12px; } #livesearch a:hover{ text-decoration: underline; color: #505050; } #header { text-decoration: none; outline: none; color: #808080; font-family: arial; font-size: 12px; } .tablestyle { text-decoration: none; outline: none; color: #808080; font-family: arial; font-size: 12px; text-align: left; } #headertable { color: #808080; font-family: arial; font-size: 11px; } </style> <script type="text/javascript"> function showResult(str) { if (str.length==0) { document.getElementById("livesearch").innerHTML=""; document.getElementById("livesearch").style.border="0px"; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("livesearch").style.border="1px solid #A5ACB2"; } } xmlhttp.open("GET","livesearch.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form action=""> <input type="text" size="30" onkeyup="showResult(this.value)" value='Sök här...' onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}" /> <div id="livesearch"></div> </form> </body> </html>
-
Haha, oh sorry. What I meant was that "false" didn't gave any value while "true" gave "1" (I tested debugging with die()). What is the problem?
-
Ok, I changed the code a little bit. while I was debugging, I noticed that $_SESSION['logged_in'] = false; doesn't show anything while $_SESSION['logged_in'] = true shows "1". if($_SESSION['password'] != $pass) {... //does work <?php include("structure.php"); include("session.php"); global $session; ?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> <link rel='stylesheet' href='http://mindu.mine.nu/amazing_solutions/gallo_negro/css/style.css' type='text/css' /> <title>Gallo Negro</title> </head> <body> <div id="sitecontainer"> <div id="contentcontainer"> <div id="content"> <div id="center_box"> <?php if ($session->logged_in==false ) { ?> <h1>VÄLKOMMEN ADMINS: LOGGA IN!</h1> <form action="process.php" method="post"/> <input type="password" name="pass" maxlength="30" onBlur="if(this.value=='')this.value='Lösenord123';" onClick="if(this.value=='Lösenord123')this.value='';" value="Lösenord123"/> <input type="submit" value="Logga in" name="sublogin"/> <?php } else{ ?> <p>Inloggad</p> <a href="process.php">Logga ut</a> <?php } ?> </div><!--end of #center_box --> </div><!--end of #content --> </div><!--end of #contentcontainer --> <?php footer();?> </div><!--end of #sitecontainer --> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"></script> <script type="text/javascript" src="safe-ajax.js"></script> </body> </html> <?php include("session.php"); class Process { /* Class constructor */ function Process(Session $session){ /* User submitted password form */ if(isset($_POST['pass'])){ $this->procLogin(); } /* User is directed here because he want's to log out*/ else if($session->logged_in==true){ $this->procLogout(); } /** * Should not get here, which means user is viewing this page * by mistake and is redirected. */ else{ header("Location: google.se"); } } function procLogin(Session $session){ /*Login attempt*/ $retval = $session->login($_POST['pass']); /* Login successful */ if($retval==true){ $session->logged_in=true; header("Location: http://mindu.mine.nu/amazing_solutions/gallo_negro/gallologin.php"); } /* Login failed */ else{ $session->logged_in=false; header("Location: http://mindu.mine.nu/amazing_solutions/gallo_negro/gallologin.php"); } function procLogout(Session $session){ $retval = $session->logout(); header("Location: http://mindu.mine.nu/amazing_solutions/gallo_negro/gallologin.php"); } } } /* Initialize process */ $process = new Process; ?> <?php class Session { var $logged_in; var $password; var $referrer; var $url; //The page url current being viewed /* Class constructor */ function Session(){ $this->startSession(); } function startSession(){ session_start();//Tell PHP to start the session $_SESSION['password'] = "password"; $password=$_SESSION['password']; /* Determine if user is logged in */ //$this->logged_in = $this->checkLogin(); /* Set referrer page */ if(isset($_SESSION['url'])){ $this->referrer = $_SESSION['url']; }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; } function login($pass){ /* Password error checking */ if($_SESSION['password'] != $pass) { $_SESSION['logged_in'] = false; return false; } /* password correct, register session variables */ $this->password = $_SESSION['password']; /* Login completed successfully */ $_SESSION['logged_in'] = true; return true; } function logout(){ unset($_SESSION['logged_in']); /* Reflect fact that user has logged out */ $this->logged_in = false; } } $session = new Session; ?>
-
The process.php is activated everytime I send the form: <form action="process.php" method="post"/> or everytime I click on the logut link
-
I'm trying to make a simple password protected (login) site, but the variable "$session->logged_in" doesn't seem to get any values (either true or false) the form <?php include("structure.php"); include("session.php"); global $session; ?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> <link rel='stylesheet' href='http://mindu.mine.nu/amazing_solutions/gallo_negro/css/style.css' type='text/css' /> <title>Gallo Negro</title> </head> <body> <div id="sitecontainer"> <div id="contentcontainer"> <div id="content"> <div id="center_box"> <?php if (!$session->logged_in ) { ?> <h1>VÄLKOMMEN ADMINS: LOGGA IN!</h1> <form action="process.php" method="post"/> <input type="password" name="pass" maxlength="30" onBlur="if(this.value=='')this.value='Lösenord123';" onClick="if(this.value=='Lösenord123')this.value='';" value="Lösenord123"/> <input type="submit" value="Logga in" name="sublogin"/> <?php } else{ ?> <p>Inloggad</p> <a href="process.php">Logga ut</a> <?php } ?> </div><!--end of #center_box --> </div><!--end of #content --> </div><!--end of #contentcontainer --> <?php footer();?> </div><!--end of #sitecontainer --> </body> </html> process.php <?php include("session.php"); class Process { /* Class constructor */ function Process(){ global $session; /* User submitted password form */ if(isset($_POST['pass'])){ $this->procLogin(); } /* User is directed here because he want's to log out*/ else if($session->logged_in){ $this->procLogout(); } /** * Should not get here, which means user is viewing this page * by mistake and is redirected. */ else{ header("Location: google.se"); } } function procLogin(){ global $session; /*Login attempt*/ $retval = $session->login($_POST['pass']); /* Login successful */ if($retval==true){ $session->logged_in=true; header("Location: http://mindu.mine.nu/amazing_solutions/gallo_negro/gallologin.php"); } /* Login failed */ else{ $session->logged_in=false; header("Location: http://mindu.mine.nu/amazing_solutions/gallo_negro/gallologin.php"); } function procLogout(){ global $session; $retval = $session->logout(); header("Location: main.php"); } } } /* Initialize process */ $process = new Process; ?> session.php <?php class Session { var $logged_in; var $password; var $referrer; var $url; //The page url current being viewed /* Class constructor */ function Session(){ $this->startSession(); } function startSession(){ session_start();//Tell PHP to start the session $_SESSION['logged_in'] = false; $_SESSION['password'] = "password"; $password=$_SESSION['password']; /* Determine if user is logged in */ //$this->logged_in = $this->checkLogin(); /* Set referrer page */ if(isset($_SESSION['url'])){ $this->referrer = $_SESSION['url']; }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; } function login($pass){ /* Password error checking */ if($_SESSION['password'] != $pass) { return false; } /* password correct, register session variables */ $this->password = $_SESSION['password']; /* Login completed successfully */ return true; } } $session = new Session; ?>
-
I have this problem whenever I zoom out in the browser (FF). The div-boxes that is close to the right borders jumps down to the next vertical line. See for yourself: http://mindu.mine.nu/amazing_solutions/gallo_negro/main.php The images on the top, the last link in the menu does just that and the right column in the middle seems to draw closer to the right corner. --- The other problem I have is centering two columns in a div-box. I've managed to center it, but it seems like the wrong way of doing it? div#boxcontainer{ position:absolute; left:50%; margin-left:-460px; margin-top:10px; } div#left_box { float:left; height:700px; width:450px; background-image:url("http://mindu.mine.nu/amazing_solutions/gallo_negro/img/opacity70.png"); background-repeat:repeat; color:#FFF; border:1px solid #3e3e3e; text-align:justify; margin-right:20px; } div#right_box { float:left; height:700px; width:450px; background-image:url("http://mindu.mine.nu/amazing_solutions/gallo_negro/img/opacity70.png"); background-repeat:repeat; color:#FFF; border:1px solid #3e3e3e; }
-
I've just followed this tutorial on how to make captcha: http://www.webcheatsheet.com/PHP/create_captcha_protection.php --- Here's how it looks like on my page: http://81.226.101.66/projektarbete/benni/TEST/register.php --- Now the problem is, the session variable "$_SESSION["security_code"]" that is created when the image is created in "create_image.php". When I run this file in the browser the variable does update to what is written in the image. When I run the "register.php" the image refreshes, but the variable $_SESSION["security_code"] remains the same. I think that the problem is that the session variable isn't updated because "create_image.php" is never used execept in<img id="imgCaptcha" src="captcha/create_image.php" >, that's only the img and not the code in that file. Please help! --- Here's the code: create_image.php <?php //Start the session so we can store what the security code actually is session_start(); //Set the session to store the security code $_SESSION["security_code"] = $security_code; //Send a generated image to the browser create_image(); exit(); function create_image() { global $security_code; //Let's generate a totally random string using md5 $md5_hash = md5(rand(0,999)); //We don't need a 32 character long string so we trim it down to 5 $security_code = substr($md5_hash, 15, 5); //Set the image width and height $width = 100; $height = 20; //Create the image resource $image = ImageCreate($width, $height); //We are making three colors, white, black and gray $white = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); $grey = ImageColorAllocate($image, 204, 204, 204); //Make the background black ImageFill($image, 0, 0, $black); //Add randomly generated string in white to the image ImageString($image, 3, 30, 3, $security_code, $white); //Tell the browser what kind of file is come in header("Content-Type: image/jpeg"); //Output the newly created image in jpeg format ImageJpeg($image); //Free up resources ImageDestroy($image); } ?> part of register.php <?php include("include/session.php"); ?> <p>Anti-Spamskydd</p> <p> <img id="imgCaptcha" src="http://mindu.mine.nu/projektarbete/benni/TEST/captcha/create_image.php" > <?php echo $_SESSION["security_code"]; ?> <input id="btnCaptcha" type="button" value="Ladda om" name="btnCaptcha" onclick="getParam(document.frmCaptcha)" /><br/> <input type="text" name="captcha" maxlength="30" value="<?php echo $form->value("captcha"); ?>"><?php echo $form->error("captcha"); ?> </p> <p class="textinput"><input type="hidden" name="subjoin" value="1"><input type="submit" value="Registrera!"></p> </form> part of session.php /* Captcha error checking */ $field = "captcha"; $captcha=$_REQUEST["captcha"]; $sec_code=$_SESSION["security_code"]; if ( ($_REQUEST["captcha"] == $_SESSION["security_code"]) && (!empty($_REQUEST["captcha"]) && !empty($_SESSION["security_code"])) ) { $this->referrer = "http://81.226.101.66/projektarbete/benni/TEST/register.php"; // The captcha code is right, go back to register.php } else{ if(!$subcaptcha || strlen($subcaptcha = trim($subcaptcha)) == 0){ // If the field is empty, display error $form->setError($field, "* skriv in kod $sec_code"); $this->referrer = "http://81.226.101.66/projektarbete/benni/TEST/register.php"; } else{ $form->setError($field, "* Fel kod $captcha , $sec_code "); // Else the captcha is wrong, display error $this->referrer = "http://81.226.101.66/projektarbete/benni/TEST/register.php"; } } ajax_captcha.js //Gets the browser specific XmlHttpRequest Object function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); //Mozilla, Safari ... } else if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); //IE } else { //Display our error message alert("Your browser doesn't support the XmlHttpRequest object."); } } //Our XmlHttpRequest object var receiveReq = getXmlHttpRequestObject(); //Initiate the AJAX request function makeRequest(url, param) { //If our readystate is either not started or finished, initiate a new request if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) receiveReq.open("POST", url, true); //Set the function that will be called when the XmlHttpRequest objects state changes receiveReq.onreadystatechange = updatePage; receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); receiveReq.setRequestHeader("Content-length", param.length); receiveReq.setRequestHeader("Connection", "close"); //Make the request receiveReq.send(param); } } //Called every time our XmlHttpRequest objects state changes function updatePage() { //Check if our response is ready if (receiveReq.readyState == 4) { //Get a reference to CAPTCHA image img = document.getElementById('imgCaptcha'); //Change the image img.src = 'http://81.226.101.66/projektarbete/benni/TEST/captcha/create_image.php?' + Math.random(); } } //Called every time when form is perfomed function getParam(theForm) { //Set the URL var url = 'include/session.php'; //Set up the parameters of our AJAX call var postStr = theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value ); //Call the function that initiate the AJAX request makeRequest(url, postStr); }
-
I've figured out that in Internet Explorer 7 the drop down menu with: div#menu li:hover ul { display:block;} behaves as if : div#menu li:hover ul { display:inline;} --- is there any compatibility fault with display:block?
-
I've just finished the structure of my site. But my drop-down menus displays and behaves weirdly in Internet Explorer 7. I figured that I can boycott Internet Explorer 6, but not IE7 because many ppl still use the browser (like the 3rd most used). http://mindu.mine.nu/projektarbete/benni/TEST/structure.php Any idea?