PHP - Problems With Session Variables On .php5 Pages
Most of my website is written in php4. My hosting server has support for both 4 and 5 just by changing file extension. .php which is the default supports 4, .php5 of course supports 5. The problem I am having is that the pages with the .php5 extensions are not recognizing session variables. Is there something I should be doing differently in 5 for my session variables?
For example a variable request like this returns 0 print $_SESSION['FULLNAME']; Please Help!! Thank you in advance? Similar TutorialsHi I am having issues with the following code. I cannot get the table to produce a subtotal multiplying the value of 'ITEMQTY' which is a text field in the form in which the user enters by the 'ITEMPRICE' field which value is located in a text document. <h1>SHOPPING CART</h1><img src="images/cart.png" alt="Cart" width="100" height="100"/> <a href="browse_index.php">CLICK HERE TO CONTINUE SHOPPING</a> <?php if(isset($_POST['submit'])) { $itemname = $_POST['h1']; //echo $_SESSION['itemname'][$itemname]; unset($_SESSION['itemqty'][$itemname]); unset($_SESSION['itemprice'][$itemname]); unset($_SESSION['itemname'][$itemname]); } echo "<br/><br/>"; echo "<table border='8' cellpadding='10' >"; echo "<tr><th>Name</th><th>Quantity</th><th>Price</th><th>Subtotal</th></tr>"; foreach($_SESSION['itemname'] as $key => $value) $subtotal = ($_SESSION['itemprice']*($_SESSION['itemqty']; { echo '<tr> <td>'.$_SESSION['itemname'][$key].'</td> <td><input type="text" name="t1" value='.$_SESSION['itemqty'][$key].'></td> <td>'.$_SESSION['itemprice'][$key].'</td> <td>'.$_SESSION['h2'][$key].'</td> <td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="h1" value='.$key.'></td> </tr> <tr><form id="t1" method="post" action="summary.php" name="t1"><input type="submit" name="order" value="SUBMIT ORDER"></tr>'; } echo "</table>"; ?> I have a small php upload/download script, it always worked on older php4 -5 but not on php5.3 ,gobal varitables must be on , I dont know to much about php and was hoping someone will look at at and let me know what to change to make it work on php5.3 or higher..............................THANKS! for any help in fixing this issue
<body link="#FFFF00" vlink="#FF0000" alink="#FFFF00"><? $extlimit = "yes"; //Do you want to limit the extensions of files uploaded $limitedext = array(".zip",".sim",".car",".jpg",".gif"); //Extensions you want files uploaded limited to. $sizelimit = "no"; //Do you want a size limit, yes or no? $sizebytes = "30033000"; //size limit in bytes $dl = "xxxxxxxxxxx"; //url where files are uploaded $absolute_path = "xxxxxxxxxxx"; //Absolute path to where files are uploaded $websiteurl = "xxxxxxxx"; //Url to you website $websitename = "Car File Manger"; if (!isset($action)) { $action = ""; } switch($action) { default: echo" <html> <head> <title>Upload Or Download</title> </head> <body> <a href=$PHP_SELF?action=upload>Upload</a> | <a href=$PHP_SELF?action=download>Download</a> | <a href=$websiteurl>Return to $websitename</a> <br><br> </body> </html>"; break; case "download": echo " <html> <head> <title>File Download</title> </head> <body><a href=$PHP_SELF?action=upload>Upload File</a> | <a href=$websiteurl>Return to $websitename</a>"; $list = "<table width=500 border=0 bordercolor=#000000 style=\"border-collapse: collapse\">"; $list .= "<tr><td width=500><center><b>Click To Download</b></center></td></tr>"; $dir = opendir($absolute_path); while($file = readdir($dir)) { if (($file != "..") and ($file != ".")) { //Download files with spaces fix by Kokesh $list .= "<tr><td width=700><a href='$dl/$file'>$file</a></center></td></tr>"; } } $list .= "</table>"; echo $list; echo" <br><br> </body> </html>"; break; case "upload": echo" <html> <head> <title>File Upload</title> </head> <body> <form method=POST action=$PHP_SELF?action=doupload enctype=multipart/form-data> <p>File to upload:<br> <input type=file name=file size=30> <p><button name=submit type=submit> Upload </button> </form> <br><br> </body> </html>"; break; //File Upload case "doupload": $dir = "dir"; if ($file != "") { if (file_exists("$absolute_path/$file_name")) { die("File already exists"); } if (($sizelimit == "yes") && ($file_size > $sizebytes)) { die("File is to big. It must be $sizebytes bytes or less."); } $ext = strrchr($file_name,'.'); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { die("The file you are uploading doesn't have the correct extension."); } @copy($file, "$absolute_path/$file_name") or die("The file you are trying to upload couldn't be copied to the server"); } else { die("Must select file to upload"); } echo " <html> <head> <title>File Uploaded</title> </head> <body>"; echo $file_name." was uploaded"; echo "<br> <a href=$PHP_SELF?action=upload>Upload </a> | <a href=$PHP_SELF?action=download> Download </a> | <a href=$websiteurl> Return to $websitename</a><br><br> </body> </html>"; break; } ?> Edited by Ch0cu3r, 01 September 2014 - 06:05 AM. Hello. Basically I've created a login script. Works great. It sends users to different locations depending on what type of user they are. Now I have also created a Members account. Upon logging in this user should go to the members area. That all works fine! In the login script i stored a few session variable like username, access_level and so on. Now in the members area I am trying to make the page echo the name of the current user. I have been stairing at my code too long and can no longer see why nothing is echo'ing. Any ideas. I thought that the session_start() would continue the session in the next page and throughout the site until the person logs off and runs the session_destroy()! Is this not correct. First ill post the login script <?php include('database.php'); session_start(); if(isset($_POST['submit3'])) { $email = stripslashes($_POST['email3']); $password = stripslashes($_POST['password3']); $email = mysql_real_escape_string($_POST['email3']); $password = md5($password); $CheckUser = "SELECT * FROM Members WHERE email='".$email."' AND password='".$password."'"; $userDetails2 = mysql_query($CheckUser); $userInfo = mysql_fetch_array($userDetails2); $count = mysql_num_rows($userDetails2); if($count != 0) { $_SESSION['username'] = $userInfo['username']; $_SESSION['usertype'] = $userInfo['usertype']; $_SESSION['access_level']= $userInfo['access_level']; if($userInfo['usertype']== 'Member') { header('Location: members/index.php'); } else if($userInfo['usertype'] == 'Owner') { header('Location: owner/index.php'); } else if($userInfo['usertype'] == 'Corporation') { header('Location: corporation/index.php'); } else if($userInfo['usertype'] == 'Administrator') { header('Location: owner/admin/index.php'); } else if($userInfo['usertype'] == 'Staff') { header('Location: owner/staff/index.php'); } } else { $message = "incorrect login details"; } } ?> now ill post the members page <?php include('../database.php'); session_start(); ?> <head> <link href="stylz.css" rel="stylesheet" type="text/css" /> <link href="reset.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"> WELCOME TO THE MEMBERS AREA <?php $_SESSION['username']; ?> <?php include('../title.php');?> <?php include('../nav.php');?> <div id="test"></div> <?php include('../footer.php');?> </div> </body> </html> Hi, I have built a registration and login system for a website, part of which I wish to protect certain pages. The registration systems works well, as does the login BUT I am having difficulty with the next stage. How do I then 'capture' the username and password that were entered by the user and get the PHP page I want to protect to check that these are valid? I guess it is a piece of code I need to put in the top of the protected page? Here is the final piece of code (which then includes a link to the page I want to protect) from the login page which includes session_register, but then how can I use this information in the page I wish to protect? //Now if everything is correct let's finish his/her/its login session_register("username", $username); session_register("password", $password); echo "Welcome, ".$username." please continue onto our ".$sub." membership area...<a href=".$index.">click here</a>"; } Thanks, Simon I have a script that was written and tested on another server, but now when I transferred it to the live server, session values are not being passed. I made a couple test pages to check and confirmed that the only issue is the session variables. Here is the test I performed. Please tell me what I'm missing: page1.php <? session_start(); $_SESSION['var1'] = 'testing'; print_r($_SESSION); ?> Returns: Array ( [var1] => testing ) page2.php <? session_start(); print_r($_SESSION); ?> Returns: Array () Hi guys, I've been going crazy over this and I'm hoping someone can help me. I'm making a website for a friend and I'm stuck on sending the model over to the contact page (from one form to another on a different page using $_POST). Here is the website : www.ipgetter.com/test I have successfully posted the Make variable to the contact us page, but I can't get the model sent over (the select boxes have different names). Example: Code: [Select] <select class="form-dropdown" style="width:150px" id="input_2" name="q2_make"> <option selected="selected" value="Alfa Romeo"> Alfa Romeo </option> <option value="Aston Martin"> Aston Martin </option> <option value="Audi"> Audi </option> <option value="Bently"> Bently </option> <option value="BMW"> BMW </option> <option value="Chevrolet"> Chevrolet </option> <option value="Chrysler"> Chrysler </option> <option value="Citroen"> Citroen </option> <option value="Ferrari"> Ferrari </option> <option value="Fiat"> Fiat </option> <option value="Ford"> Ford </option> <option value="Honda"> Honda </option> <option value="Hyundai"> Hyundai </option> <option value="Infiniti"> Infiniti </option> <option value="Isuzi"> Isuzi </option> <option value="Jaguar"> Jaguar </option> <option value="Jeep"> Jeep </option> <option value="Kia"> Kia </option> <option value="Lamborghini"> Lamborghini </option> <option value="Land Rover"> Land Rover </option> <option value="Lexus"> Lexus </option> <option value="Lotus"> Lotus </option> <option value="Maserati"> Maserati </option> <option value="Mazda"> Mazda </option> <option value="Mclaren"> Mclaren </option> <option value="Mercedes-Benz"> Mercedes-Benz </option> <option value="MG"> MG </option> <option value="Mini"> Mini </option> <option value="Mitsubishi"> Mitsubishi </option> <option value="Nissan"> Nissan </option> <option value="Peugeot"> Peugeot </option> <option value="Porsche"> Porsche </option> <option value="Renault"> Renault </option> <option value="Rolls-Royce"> Rolls-Royce </option> <option value="Seat"> Seat </option> <option value="Skoda"> Skoda </option> <option value="Smart"> Smart </option> <option value="Ssangyong"> Ssangyong </option> <option value="Subaru"> Subaru </option> <option value="Suzuki"> Suzuki </option> <option value="Toyota"> Toyota </option> <option value="Vauxhall"> Vauxhall </option> <option value="Volkswagen"> Volkswagen </option> <option value="Volvo"> Volvo </option> <option value="Other"> Other </option> </select> That's the make, as for the model, the select boxes have different names so how am I supposed to capture the users selection and POST it? Code: [Select] <li class="form-line" id="id_3"> <label id="label_3" for="input_3"></label> <div id="cid_3" class="form-input"> <select class="form-dropdown" style="width:150px" id="input_3" name="q3_model"> <option selected="selected" value="147"> 147 </option> <option value="159"> 159 </option> <option value="8C"> 8C </option> <option value="Breva"> Breva </option> <option value="Giulietta"> Giulietta </option> <option value="Mito"> Mito </option> <option value="Other"> Other </option> </select> </div> </li> <li class="form-line" id="id_4"> <label id="label_4" for="input_4"></label> <div id="cid_4" class="form-input"> <select class="form-dropdown" style="width:150px" id="input_4" name="q4_model4"> <option selected="selected" value="Cygnet"> Cygnet </option> <option value="DB9"> DB9 </option> <option value="DBS"> DBS </option> <option value="Rapide"> Rapide </option> <option value="Vantage"> Vantage </option> <option value="Virage"> Virage </option> <option value="Other"> Other </option> </select> </div> </li> I want to post only the selected make/model depending on the user selection. So my question is, how can I send the users chosen model selection over to the contact page form where there is more than one different select box? These select boxes are conditional so when you select "other" as make or model make/model, you may type one in. I'd like to send that also. Any help is appreciated guys, thanks so much. I'm trying to make a "sort by" script to sort posts. I'm hoping someone can help me figure out a small glitch. For some reason I'm getting multiple variables in the url as if the page doesn't reload. The code is $uri = $_SERVER['REQUEST_URI']; //gets url of current page <li><a href="<?php echo $uri; ?>&sort=New">Most Recent</a></li> <li><a href="<?php echo $uri; ?>&sort=Popular">Popular</a></li> <li><a href="<?php echo $uri; ?>&sort=Discussed">Discussed</a></li> if for example I choose to sort by "Popular" the url output will be Code: [Select] http://localhost/mysite/single_cat.php?cat=57&sort=Popular but then when I click let's say "Discussed" a new sort variable is added with the existing one. Code: [Select] http://localhost/mysite/single_cat.php?cat=57&sort=Popular&sort=Discussed and below I'm querying posts based on the sort variable.. for example.. if ($sort == "Popular") { //db connection $sql = "SELECT * FROM posts WHERE cat_id = '$cat' AND views >= 2 ORDER BY views DESC, post_date DESC"; //while loop, etc }//end else if I'm not sure what I did wrong.. How do I get just one "?sort=" url variable? Hi there,
I want to pass a input variable from login_success.php which will be sent to sqlprocess.php as the variable 'SQLinput';
sqlprocess.php
$link = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $query = $_REQUEST['SQLinput']; //You don't need a ; like you do in SQL $result = mysql_query($query); $numfields = mysql_num_fields($result);login_sucess.php <form action="" method="post" <label> <span>SQL Input :</span> <input type ="text" id="message" name="SQLinput" placeholder="Input SQL"></textarea> </label> <label> <span>SQL Output :</span> <output id="text" id="SQLoutput" ></input> <script type="text/javascript" charset="utf-8"> // handles the click event for link 1, sends the query function getOutput() { getRequest( 'sqlprocess.php', // URL for the PHP file drawOutput, // handle successful request drawError // handle error ); return false; } // handles drawing an error message function drawError () { var container = document.getElementById('output'); container.innerHTML = 'Bummer: there was an error!'; } // handles the response, adds the html function drawOutput(responseText) { var container = document.getElementById('output'); container.innerHTML = responseText; } // helper function for cross-browser request object function getRequest(url, success, error) { var req = false; try{ // most browsers req = new XMLHttpRequest(); } catch (e){ // IE try{ req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { // try an older version try{ req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ return false; } } } if (!req) return false; if (typeof success != 'function') success = function () {}; if (typeof error!= 'function') error = function () {}; req.onreadystatechange = function(){ if(req .readyState == 4){ return req.status === 200 ? success(req.responseText) : error(req.status) ; } } req.open("GET", url, true); req.send(null); return req; } </script> <a href="#" onclick="return getOutput();"><button type="submit" id="search_btn" value="Submit">Submit</button> </a> <div id="output">waiting for action</div>Prior to the JS code - I was able to peform this action - however the JS code enables me to post the query onto the same page. I would like essentially like to query the database through an input box and output the same result on the same page. Thanks! Hi guys,
I am having a problem transferring data between pages, using PHP sessions. I have a HTML SELECT drop-down to let user set the number of posts per page to display. <form method="POST" style="margin:auto;position:relative;width:35%;padding:17px;top:47px;"> <span>select posts-per-page:</span> <select name="ppp"> <option selected disabled>--select ppp--</option> <option value=10>10</option> <option value=15>15</option> <option value=20>20</option> <option value=50>50</option> <option value=100>100</option> </select> <input type="submit" name="submit" value="OK"/> </form> I want to transfer the value selected by user to a session so that I can load the value in other pages. The value of posts per page is carried by variable $ppp; so, file1 contains the code $_SESSION['ppp'] = $ppp; That seems to work great; the system updates correctly the session's value as user submits different numbers of posts-per-page.
The problem is in page2.php: it doesn't update to the new user's selection; I already have a session active in that page so I don't need session_start(). To call the session, I use the line $ppp=$_SESSION['ppp']; When user changes the selection from 50 to 100 posts per age, for example, the value of page1.php changes as expected, but the value transferred to page2.php doesn't change, appears to remain with the default value the page loads with. I don't know if the problem is that I already have a session going. Can you have more than one session running simultaneously in a page? Can anybody help? Thanks in advance!
Sept I am creating a webpage for my golf league and some of the information(variables) such as Name, Address and email, must be reused across multiple pages for different outputs. May question is "Can I, or is there a way to reUse variables across multiple pages. "Do I need to create a session and make everything session variables"? "Should I link to a database and call the information when needed"? Any explanation would be greatly appreciated. Hi Can some steer me in the right direction. I am having issues subtotaling 2 session variables: <td>'.$_SESSION['itemqty'][$key].'*'.$_SESSION['itemprice'][$key].'</td> Can you advise if I am doing this right? Cheers Say I have a dropdown menu consisting of user specific options. I need to be able to set a session variable depending on the option chosen & then re-access it on the following page. Can someone give me a crash course on how to utilize session variables? they recently reset my website so my php.ini file has been adjusted. One of my sites is no longer passing a session variable to the next page. I am sure its one of the settings being reset. here is the data from my phpinfo file. Anything that looks off to anyone? session Session Support enabled Registered save handlers files user sqlite Registered serializer handlers php php_binary wddx Directive Local Value Master Value session.auto_start Off Off session.bug_compat_42 On On session.bug_compat_warn On On session.cache_expire 180 180 session.cache_limiter nocache nocache session.cookie_domain no value no value session.cookie_httponly Off Off session.cookie_lifetime 0 0 session.cookie_path / / session.cookie_secure Off Off session.entropy_file no value no value session.entropy_length 0 0 session.gc_divisor 100 100 session.gc_maxlifetime 1440 1440 session.gc_probability 1 1 session.hash_bits_per_character 4 4 session.hash_function 0 0 session.name PHPSESSID PHPSESSID session.referer_check no value no value session.save_handler files files session.save_path /home/users/web/b535/ipw.plevtech/public_html/cgi-bin/tmp /home/users/web/b535/ipw.plevtech/public_html/cgi-bin/tmp session.serialize_handler php php session.use_cookies On On session.use_only_cookies Off Off session.use_trans_sid 0 0 ...anyone know anything about Internet Explorer not printing values from session variables. It works on Firefox but not on Internet Explorer. The session variable value works find on the web page but click on Print preview and it dissapears and will not print. Hi. I'm brand new to this forum, so sorry if I do something wrong... I'm someone who has thought myself to code in php to add dynamic objects to my basic static websites. I have had no formal education. This is not my first project however. I'm having problems with session variables working fine up to a point when I call a new file and then all my session variables are lost. I have tried everything, but cannot keep them alive when I get into this or any other new file. I display a form, get user data submitted, then display a next form and after the user submits this next form all the session variables are lost. Anyone have any idea what is killing my session variables? Thanks in advance. Hi, I am facing problems in destroying the session variables in my logout file .I have used session_id() in my php files for ex $sid = session_id().Now when I click on logout I naviagte to my index file but the session variable $sid still remain.I have chkd it.I have kept session_start() function in a file and I am including that file in every php by require_once function.The file is palced in Includes folder..is it causing the problem?? please help me out Also can I use session_start() more than once in a single php file? My logout file is : <?php session_start(); session_destroy(); header("location:index.php"); exit(); ?> Hi All! I've written up a script for my website. It\ is basically a virtual job quest. My queries are all correct it just isn't registering the variable for the session. It is $-SESSION[theid']. I want to be bale to use it in my table but I get an error. How do I write this in my SQL query for it to work. The page (when no errors), doesn't show my data. Here is my ocde: Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content><content><center><font size=6>Messages</font><br><br></center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar><img src=/images/layout/player.gif><a href=status.php>$showusername</a>.......................<img src=/images/layout/coin.gif> $scredits</ubar><content><center><font size=6>Basic Quests</font><br><br>"; $startjob = $_POST['submit']; $jobq = "SELECT * FROM jobs WHERE username='$showusername'"; $job = mysql_query($jobq); $jobnr = mysql_num_rows($job); if($jobnr == "0") { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="submit" name="submit" value="Start Job"></form> <?php } if(isset($startjob)) { $initemidq = "SELECT * FROM items ORDER BY RAND() LIMIT 1"; $initemid = mysql_query($initemidq); while($ir = mysql_fetch_array($initemid)) { $ids = $ir['itemid']; } mysql_query("INSERT INTO jobs (username, item, time, completed) VALUES ('$showusername', '$ids', 'None', 'No')"); $wegq = "SELECT * FROM items WHERE itemid='$ids'"; $weg = mysql_query($wegq); while($wg = mysql_fetch_array($weg)) { $im = $wg['image']; $nm = $wg['name']; $id = $wg['itemid']; } $_SESSION['theid'] = $id; echo "<font color=green>Success! You have started this Job!</font><br><br>Please bring me this item: <b>$nm</b><br><br><img src=/images/items/$im><br><br><br>"; echo $_SESSION['theid']; } if($jobnr == "1") { $finish = $_POST['finish']; $okgq = "SELECT * FROM items WHERE itemid='$yes'"; $ok = mysql_query($okgq); while($ya = mysql_fetch_array($ok)) { $okname = $ya['name']; $okid = $ya['itemid']; $okimage = $ya['image']; } echo "Where is my <b>$okname</b>?<br><br><img src=/images/items/$okimage><br><br><br>"; echo $_SESSION['theid']; ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> <input type="submit" name="finish" value="I have the Item"></form> <?php } } if(isset($finish)) { $cinq = "SELECT * FROM uitems WHERE theitemid='$_SESSION[theid]'"; $cin = mysql_query($cinq); $connr = mysql_num_rows($cin); if($connr != "0") { echo "<font color=green>Success! You have the item.</font>"; } else { echo "<font color=red>Error! You do not have my item!</font>"; } } ?> . I basically just want to know how I can set this session as a variable. Also..I have a user login on every page and I want to be able to destroy JUST THE "theid" session and NOT the username session. How would I do that too? thanks for the help in advance! Hi, I'm having a wierd problem related to session variables. It looks like variables would get duplicated inside same session, which of course should not be possible. Background: This problem exists on one page script which creating a quote request system where users can select different products and get quote for those. Quote system creates quote ID per customer and all products selected in one session should go under the same quote ID. Problem is that sometimes when user selects products second quote ID is created and after that products are randomly added into both of quotes. While trying to solve this problem I added simple logs to see what's going on, those are added below. Problem seems to be caused by duplicated session variables. At somepoint it looks like session variables are not defined any more and new quote ID is created. After that the old and new session variables seems to be used randomly. To demonstrate the problem I added session variable called 'counter' which is defined if it does not exist and incremented always when page is reloaded by submitting the form. As you can see from below logs the 'counter' variable seems to have duplicate values, see the quote value to separate two different session variable "sets". <?php session_start(); echo "\n Current session id: ".session_id(); echo "\n _SESSION['quote']: ".$_SESSION['quote']; $_SESSION['counter'] = isset($_SESSION['counter'])? $_SESSION['counter'] +1 : 0; echo "\n _SESSION['counter']: ".$_SESSION['counter']; Output when page is reloaded(form submitted): Current session id: r5i15u4s9e20ud4j6jke8ln376 $_SESSION['quote']: $_SESSION['counter']: 0 set _SESSION['quote']: 984 Current session id: r5i15u4s9e20ud4j6jke8ln376 $_SESSION['quote']: $_SESSION['counter']: 0 set _SESSION['quote']: 985 Current session id: r5i15u4s9e20ud4j6jke8ln376 $_SESSION['quote']: 985 $_SESSION['counter']: 1 Current session id: r5i15u4s9e20ud4j6jke8ln376 $_SESSION['quote']: 985 $_SESSION['counter']: 2 Current session id: r5i15u4s9e20ud4j6jke8ln376 $_SESSION['quote']: 984 $_SESSION['counter']: 1 Current session id: r5i15u4s9e20ud4j6jke8ln376 $_SESSION['quote']: 985 $_SESSION['counter']: 3 Current session id: r5i15u4s9e20ud4j6jke8ln376 $_SESSION['quote']: 984 $_SESSION['counter']: 2 Could anyone explain how the 'counter' can behave such way inside same session (based on session ID)? This is far beyond my knowledge and I would highly appreciate any advice or tip how to solve this porblem. Thanks. BestRegards, Laowai I am finally making the upgrade from PHP 5.3 to PHP 7.3. When converting over the code I noticed that session some sessions are not being processed. My test code for this is below:
session_start(); include ("../includes/connect.inc"); echo "hiiiiiiii: ".$currentDate; echo "He ".$_SESSION['user']; if (isset($_SESSION['user'])) { $user = $_SESSION['user']; $currentDate = date("Y/m/d"); } else { echo "Session not started: "; }
My include is listed below: $link = mysqli_connect('localhost', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error("Connection error message")); } mysqli_select_db($link, 'dbname') or die (mysqli_error($link)); date_default_timezone_set('America/Chicago'); define ("TZ_CORRECTION", 43200); $bkcolor = "#FFFFFF"; $currentDate = (Date("Y-m-d")); I am not getting the message "Session not started or the current date from the include". If it matters I am using WAMP as my testing server Any help is greatly appreciated. Hello! I'm a bit of a novice on PHP variables still and perhaps I'm trying to run before I can walk. I have an SQL database that I am able to successfully write to without any problems. I have also created a session variable for the user id number that I am able to retrieve on a later page. My problem is that I have hit a wall when it comes to retrieving the data from the database based upon the session variable user id. Here is my code and error: $_SESSION['ID_ASSIGNED']=$_POST[KSU_ID]; //this line takes the form data and successfully assigns it to the session variable on an earlier page echo $_SESSION['ID_ASSIGNED']; //that line works normally. Here's my problem code (the line starting with $result ). The line works fine if I input: $result = mysql_query("SELECT * FROM $usertable WHERE KSU_ID='some id number'");: <?php $result = mysql_query("SELECT * FROM $usertable WHERE KSU_ID=$_SESSION['ID_ASSIGNED']"); $row = mysql_fetch_array($result); echo "<br />Participant Number:"; echo $row['ID']; echo "<br />Name: "; echo $row['lname']; echo ", "; echo $row['fname']; echo "<br />Student Number:"; echo $row['KSU_ID']; echo "<br />Age: "; echo $row['age']; echo "<br />Gender: "; echo $row['gender']; echo "<br />Grade: "; echo $row['grade']; mysql_close($con); ?> |