PHP - Losing Images After Pagination Sort.
Hello,
I am creating a simple catalog feature on my website for logging collections in a list format. Using built in pagination (cakephp) on my list to sort by name, I lose my images after the sort. Any ideas how to get around this? Here is the code. View: Code: [Select] <td><div align='center'> <?php echo $this->Html->toggleBoolean($nintendo['Nintendo']['box']); ?> </div></td> Helper: Code: [Select] function toggleBoolean($value){ if ($value == 1) return "<img src='../img/fam/tick.png' alt='Yes' />"; else return "<img src='../img/fam/cross.png' alt='No' />"; } Regards, Ash Similar TutorialsHello and Gm. I have a script (below) which paginates a mysql table. Showing 4 rows per page. It works well. <?php $sql = mysql_query("SELECT * FROM tablename ORDER BY id ASC"); $nr = mysql_num_rows($sql); if (isset($_GET['pn'])) { $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); } else { $pn = 1; } $itemsPerPage = 8; //number of rows per page $lastPage = ceil($nr / $itemsPerPage); if ($pn < 1) { $pn = 1; } else if ($pn > $lastPage) { $pn = $lastPage; } $centerPages = ""; $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; $sql2 = mysql_query("SELECT * FROM tablename ORDER BY id ASC $limit"); //second query $paginationDisplay = ""; if ($lastPage != "1"){ $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. ' '; if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; } $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; } } $outputList = ''; while($row = mysql_fetch_array($sql2)){ print "$row[permalink]"; print "$row[title]"; } ?> </div> <h2>Total Items: <?php echo $nr; ?></h2> <?php echo $paginationDisplay; ?> <?php print "$outputList"; ?> What I would like to do is have it like you see on other sites where there is a drop down menu that one can sort by a column first and it paginates after. So the url or dropdown would look something like /paginatedfile.php/column_name=title&orderby=desc And if you click page 2 you get a url like.. /paginatedfile.php/column_name=title&orderby=desc&pn=2 Can someone please help. Thanks, Chris Hi I have the following script to show images from a directory and make thumbs , but I would like to know how to sort the images from newest to oldest and how to implement it in this script
I'm a rookie at this...
Many Thanks in Advance!
<?php # SETTINGS $max_width = 800; $max_height = 600; $per_page = 10; $page = $_GET['page']; $has_previous = false; $has_next = false; function getPictures() { global $page, $per_page, $has_previous, $has_next; if ( $handle = opendir(".") ) { $lightbox = rand(); echo '<ul id="pictures">'; $count = 0; $skip = $page * $per_page; if ( $skip != 0 ) $has_previous = true; while ( $count < $skip && ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) $count++; } $count = 0; while ( $count < $per_page && ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { // make the thumbs directory if it doesn't already exist if ( ! is_dir('thumbs') ) { mkdir('thumbs'); } // make a thumbnail if it doesn't already exist if ( ! file_exists('thumbs/'.$file) ) { makeThumb( $file, $type ); } // create a link to $file, add the thumbnail echo '<li><a href="' . $file . '">'; echo '<img src="thumbs/'.$file.'" alt="" /></a></li>'; $count++; echo substr($file,strlen($folder),strpos($file, '.')-strlen($folder)); } } echo '</ul>'; while ( ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { $has_next = true; break; } } } } function getPictureType($file) { $split = explode('.', $file); $ext = $split[count($split) - 1]; if ( preg_match('/jpg|jpeg/i', $ext) ) { return 'jpg'; } else if ( preg_match('/png/i', $ext) ) { return 'png'; } else if ( preg_match('/gif/i', $ext) ) { return 'gif'; } else { return ''; } } function makeThumb( $file, $type ) { global $max_width, $max_height; if ( $type == 'jpg' ) { $src = imagecreatefromjpeg($file); } else if ( $type == 'png' ) { $src = imagecreatefrompng($file); } else if ( $type == 'gif' ) { $src = imagecreatefromgif($file); } if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) { $newW = $oldW * ($max_width / $oldH); $newH = $max_height; } else { $newW = $max_width; $newH = $oldH * ($max_height / $oldW); } $new = imagecreatetruecolor($newW, $newH); imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH); if ( $type == 'jpg' ) { imagejpeg($new, 'thumbs/'.$file); } else if ( $type == 'png' ) { imagepng($new, 'thumbs/'.$file); } else if ( $type == 'gif' ) { imagegif($new, 'thumbs/'.$file); } imagedestroy($new); imagedestroy($src); } ?> <!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" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UFT-8" /> <title>Pictures</title> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> <style type="text/css"> body { width:780px; margin:0 auto; } #pictures li { float:left; height:<?php echo ($max_height + 10); ?>px; list-style:none outside; width:<?php echo ($max_width + 10); ?>px; text-align:center; } img { border:0; outline:none; } .prev { float:left; } .next { float:right; } </style> </head> <body> <?php getPictures(); ?> <div style="clear:both"></div> <?php if ( $has_previous ) echo '<p class="prev"><a href="?page='.($page - 1).'">← Previous Page</a></p>'; if ( $has_next ) echo '<p class="next"><a href="?page='.($page + 1).'">Next Page →</a></p>'; ?> <div style="clear:both"></div> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="js/lightbox.js"></script> </body> </html> Ok the pagination part is all working fine. but i thought id be able to create a heap variables inside the loop then display the images in a table. the only trouble is all variables are grabbing the same img. i need them to grab the 10 different records. thanks Code: [Select] $sql = "SELECT * FROM mongrels_db.gallery ORDER BY id DESC LIMIT $offset, $rowsperpage "; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_array($result)) { $img1=$list['img']; $img2=$list['img']; $img3=$list['img']; $img4=$list['img']; $img5=$list['img']; $img6=$list['img']; $img7=$list['img']; $img8=$list['img']; $img9=$list['img']; $img10=$list['img']; // echo data } // end while echo "<table><tr>"; echo "<td>"."<img src='../gallery/".$img1 ."' width='100' height='100''> "."</td>"; echo "<td>"."<img src='../gallery/".$img2 ."' width='100' height='100''> "."</td>"; echo "<td>"."<img src='../gallery/".$img3 ."' width='100' height='100''> "."</td>"; echo "<td>"."<img src='../gallery/".$img4 ."' width='100' height='100''> "."</td></tr>"; echo "<tr><td>"."<img src='../gallery/".$img5 ."' width='100' height='100''> "."</td>"; echo "<td>"."<img src='../gallery/".$img6 ."' width='100' height='100''> "."</td>"; echo "<td>"."<img src='../gallery/".$img7 ."' width='100' height='100''> "."</td>"; echo "<td>"."<img src='../gallery/".$img8 ."' width='100' height='100''> "."</td>"; echo "<tr><td>"."<img src='../gallery/".$img9 ."' width='100' height='100''> "."</td>"; echo "<td>"."<img src='../gallery/".$img10 ."' width='100' height='100''> "."</td></tr>"; Hi I'm trying to setup Pagination at the bottom of the page after showing 10 images in the following script but have no clue where to start and how to implement it into the script. This is my pagination with the number bar: Code: [Select] <?php $page = $_GET['page']; $category = $_GET['cat']; $your_db = @ new mysqli("$hostname","$username", "$password"); if (mysqli_connect_errno()) { echo 'ERROR!<br />'.mysqli_connect_errno() .' - Not connected : '.mysqli_connect_error().'<br />'; die; } else { $db_connect = $your_db->select_db("database"); if (!$db_connect) { echo 'Error!'; die; } } echo '<p>'; $query = "select distinct fldCategory from tablename order by fldCategory"; $result = $your_db->query($query); $number_of_records = $result->num_rows; for ($i = 0; $i < $number_of_records; $i++) { $row = $result->fetch_assoc(); echo '<a href="page_name.php?cat='.stripslashes($row['fldCategory']).'">'; echo stripslashes($row['fldCategory']); echo '</a> / '; } echo '</p>'; if ($category) { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename where fldCategory = '$category' order by fldCategory"; } else { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename order by fldCategory"; } $result = $your_db->query($query); $number_of_records = $result->num_rows; $num_pages = $number_of_records / 7; if (($number_of_records % 7) > 0 ) { $num_pages++; } if (strlen($page) == 0) { $page = 0; } else { $page = $page * 7; } echo '<table border="1">'; $row_num = 1; $result->data_seek($page); for ($i = $page; $i < $number_of_records; $i++) { if ($row_num <= 7) { echo '<tr>'; for ($col_num = 0; $col_num < 5; $col_num++) { $row = $result->fetch_assoc(); echo '<td>'; show_image(stripslashes($row['fldIconMedium']),stripslashes($row['fldTitle'])); echo '<br />'; echo '<a href="'.stripslashes($row['fldLink']).'" target="_blank">'; echo stripslashes($row['fldTitle']); echo '</a>'; echo '</td>'; } $row_num++; echo '</tr>'; } else { break; } } echo '</table>'; for ($j = 0; $j < $num_pages; $j++) { $page_link = $j + 1; echo '<a href="page_name.php?page='.$j.'&cat='.$category.'">'.$page_link.'</a> '; } echo ' '.$number_of_records; function show_image($image_name, $alt) { if (file_exists("path_to_images/$image_name")) { $dim_img = getimagesize('path_to_images/'.$image_name); echo '<img src="path_to_images/'.$image_name.'" alt = '.$alt.' border=0 align="bottom"'; echo 'width = '. $dim_img[0] .' height = ' .$dim_img[1] . ' />'; } else echo 'NO IMAGE'; } ?> To see it in action, here is the link to the 'skill games' section of the pagination script: http://netroxy.com/games2.php?cat=skills Ok here is the issue 1. As you can see, all the results displayed in the pagination script is correct, but what confuses me is the extra blank images that continue on in the table of the pagination table. I tried replacing the queries to see if the extra blank images would be removed like this: Code: [Select] $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink from tablename where fldCategory = '$category' and length(fldIconMedium) > 0 order by fldCategory"; } else { $query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink where length(fldIconMedium) > 0 from tablename order by fldCategory"; So you see, I used 'length(fldIconMedium) > 0' making images less than 0 to see if the rest of the blank images would disappear from the cells in the table. This has not worked. Hence 'fldIconMedium' is the column for the images in the mysql database. Visit the link and you'll see the extra blank images through the results. This also applies when search for other game categories, blank images appear and I cant remove those extra blank images from the table. Hi All i am wanting a column list like this http://extensions.joomla.org/extensions basically the database is set up as (id, category, parent) I want the parent to group the category section and list like the the joomla example in three columns search various threads throughout the internet but none seem to cover this entirely can any one please help????? I am not sure If I am loosing my variable or if it is just getting cancelled out by the syntax. The error I get is this: Query string: "SELECT * FROM timeslip WHERE 1 and Initials=" ORDER BY "Date" ASC, "Cost" ASC Failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"SELECT * FROM timeslip WHERE 1 and Initials=" ORDER BY "Date" ASC, "Cost" ASC' at line 1 Initials should have the value of GEC at this moment Here is my code: $qry_str="SELECT * FROM timeslip WHERE 1 "; if($_POST['Initials']) { $Initials=$_POST['Initials']; $qry_str.='and Initials="'.$Initials . '"'; } if($_POST['Identifier']) { $Identifier=$_POST['Identifier']; $qry_str.='and Identifier LIKE "%'.$Identifier . '%"'; } if($_POST['Type']) { $Type=$_POST['Type']; $qry_str.='and Type LIKE "%'.$Type . '%"'; } if($_POST['Terms']) { $Terms=$_POST['Terms']; $qry_str.='and Terms LIKE "%'.$Terms . '%"'; } if($_POST['Memo']) { $Memo=$_POST['Memo']; $qry_str.='and Memo LIKE "%'.$Memo . '%"'; } if($_POST['date1']) { $date1=$_POST['date1']; $date2=$_POST['date2']; $start=date('Y-m-d', strtotime($date1)); $end=date('Y-m-d', strtotime($date2)); $qry_str.="and Date >= $start and Date <= $end "; } if($_POST['order1'] && $_POST['order2']) { $order1=$_POST['order1']; $order2=$_POST['order2']; $qry=$_POST['qry']; $qry_str=' "'.$qry.'" ORDER BY "'.$order1 . '" ASC, "'.$order2 . '" ASC '; } elseif(isset($_POST['order1'])) { $order1=$_POST['order1']; $qry=$_POST['qry']; $qry_str='$qry ORDER BY $order1 ASC'; } else { if(isset($_POST['order2'])) { $order2=$_POST['order1']; $qry=$_POST['qry']; $qry_str='$qry ORDER BY $order2 ASC'; } } if( !$result = mysql_query($qry_str) ) { echo "<br>Query string: $qry_str<br>Failed with error: " . mysql_error() . '<br>'; } Alright I know scraping is frowned upon.. but its for a client... Anyways.. The below is supposed to form an array $kw for output. But its breaking on line 27: Code: [Select] foreach ($kw as $keyword => $pages) Ive concluded my array is being broken and then formed into an empty string, but I can't figure out where it wen't wrong. I want to say the trouble comes from lines 20-23: Code: [Select] foreach($data as $temp) { $kx = text_between('"','"',$temp); if (is_array($kx)) $kw[key($kx)] = current($kx); } The full version.. Code: [Select] <?php function text_between($start,$end,$string) { $keyword = ''; if ($start != '') {$temp = explode($start,$string,2);} else {$temp = array('',$string);} $temp = @explode($end,$temp[1],2); $temp2 = @explode($end,$temp[1],3); $pages = (int)@str_replace(',','',$temp2[1]); if ($pages) $keyword[$temp[0]] = $pages; return $keyword; } function gsscrape($keyword) { $keyword=str_replace(" ","+",$keyword); $keyword=str_replace("%20","+",$keyword); global $kw; $data=file_get_contents('http://clients1.google.com/complete/search?hl=en&gl=us&q='.$keyword); $data=explode('[',$data,3); $data=explode('],[',$data[2]); foreach($data as $temp) { $kx = text_between('"','"',$temp); if (is_array($kx)) $kw[key($kx)] = current($kx); } } #simple to use, just use yourscriptname.php?keywords echo $_SERVER['QUERY_STRING']; if ($_SERVER['QUERY_STRING']!='') { gsscrape($_SERVER['QUERY_STRING']); foreach ($kw as $keyword => $pages) { gsscrape($keyword); } } #all results are in array $kw... echo "<pre>"; print_r($kw); echo "</pre>"; ?> I seem to be losing my array value when it comes to the "Game Time" section of my script. I am printing out the array a long the entire time and this is where I lose it and can't figure out why. <form name="form1" method="post" action=""> <span class="whitetitle">How many teams?</span> <ul class="pageitem"> <li> <SELECT name="teams" onchange="document.form1.submit();"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </SELECT> </li> </ul> </form> <? if($_POST['teams']) { ?> <form method="post" name="form2" action=""> <span class="whitetitle">Team Name</span> <?php $teams=$_POST['teams']; $count=0; while($count<$teams) { ?> <ul class="pageitem"> <li class="bigfield"> <input placeholder="Name" type="text" name="teamname[]"/> </li> </ul> <? $count++; } ?> <input type="hidden" value="<?=$teams?>" name="teams" /> <input type="submit" name="Submit" value="Next"> </form> <? } ?> <? if ($_POST['teamname']) { $teams=$_POST['teams']; $teamname=$_POST['teamname']; ?> <form name="form" method="post" action=""> <span class="name"><? print_r ($_POST['teamname']);?></span> <ul class="pageitem"> <li class="radiobutton"><span class="name">Season</span> <input name="schedule" type="radio" value="season" onClick="this.form.action='';this.form.submit()" /></li> <li class="radiobutton"><span class="name">Playoffs</span> <input name="schedule" type="radio" value="playoffs" onClick="this.form.action='';this.form.submit()"/></li> </ul> <input type="hidden" value="<?=$teams?>" name="teams" /> <input type="hidden" value="<?=$teamname?>" name="teamname" /> </form> <? } if($_POST['schedule']) { $teams=$_POST['teams']; $schedule=$_POST['schedule']; $teamname=$_POST['teamname']; ?> <form name="form4" method="post" action=""> <span class="name"><? print_r ($_POST['teamname']);?></span> <span class="whitetitle">Games per Night</span> <ul class="pageitem"> <li> <SELECT name="games" onchange="document.form4.submit();"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </SELECT> </li> </ul> <input type="hidden" value="<?=$teamname?>" name="teamname" /> <input type="hidden" value="<?=$teams?>" name="teams" /> <input type="hidden" value="<?=$schedule?>" name="schedule" /> </form> <? } if($_POST['games']) { $teams=$_POST['teams']; $schedule=$_POST['schedule']; $games=$_POST['games']; $teamname=$_POST['teamname']; $count=0; ?> <form name="form5" method="post" action=""> <span class="name"><? print_r ($_POST['teamname']);?></span> <span class="whitetitle">Times</span> <ul class="pageitem"> <? while($count<$games) { ?> <li> <input placeholder="Times" type="text" name="times[]"/> </li> <? $count++; } ?> </ul> <input type="hidden" value="<?=$teamname?>" name="teamname" /> <input type="hidden" value="<?=$teams?>" name="teams" /> <input type="hidden" value="<?=$schedule?>" name="schedule" /> <input type="hidden" value="<?=$games?>" name="games" /> <input type="submit" name="Submit" value="Next"> </form> <? } if($_POST['times']) { echo $_POST['teams']; print_r ($_POST['teamname']); echo $_POST['schedule']; echo $_POST['games']; echo implode(",",$_POST['times']); } ?> Hey there, Pretty frustrated with this. It seems so simple, but I've been staring at it and toying with it for ages, so I figured I'd post here. I have a variable called "$isTaken" that seems to be losing its value in an essential step in my function. Take a look. function subdomainTaken($inputtedSubdomain) { //Initialize $isTaken to 'true' $isTaken = true; echo "isTaken STARTS AS: <i>" . $isTaken . "</i><br />"; //FOR TESTING PURPOSES ONLY. VARIABLE HAS VALUE HERE //Check subdomain in database $subdomainDBQuery = mysql_query("SELECT * FROM `companies` WHERE company_subdomain = '$inputtedSubdomain'"); $foundResult = mysql_num_rows($subdomainDBQuery); if ($foundResult > 0) { $isTaken = true; } else { $isTaken = false; } return $isTaken; } By the time I get to the if statement, $isTaken has no value. I've echoed it to be sure. Any ideas? Thanks, Frank Alright, I've spent over a week trying to fix this now - And Im getting frustrated! I asked at other forums, I asked co-workers and I asked friends-of-friends, and nobody can explain what happens. Let's take a look at this first: $name = mysql_real_escape_string($_POST['name']); mysql_query(sprintf("UPDATE em_users SET name='%s' WHERE id='" . $in_user['id'] . "'", $name)); This will insert NO data on the Name field in the database. Obviously, I thought the $_POST variable wasn't passed correctly, but echo'ing it just before the query WILL show data. And as I said, I tried everything possible for the last week. Switching variables, adding static text on the $name variable instead of using the $_POST content (this does work). I used very very simple test data on the form, such as my name "Mark" or "test" and "hey". The query is correctly executed everytime. The truely WEIRD thing is, if I ensure there is content in $name before executing the query it will work as expected everytime. Like this: $name = mysql_real_escape_string($_POST['name']); $name && mysql_query(sprintf("UPDATE em_users SET name='%s' WHERE id='" . $in_user['id'] . "'", $name)); Of course I could do this, but I want to know why my code does or doesn't work + it's a lot of work to do for something that worked fine a week ago. It has spread to a lot of forms on my website that $_POST variables aren't processed correctly - and it happened out of nowhere. Even on codes that havnt changed in months. I really need help on fixing this! This project has been in development for nearly two years, and without a fix it's pretty much lost Afternoon, Not sure if i've been staring at the screen for too long or not, but have a log in script which saves the password as a session variable and I can pass that variable across my page like so: <?php session_start(); //Print_r ($_SESSION); echo "Erm, I have reached page.php and the password is ".$_SESSION['password']; ?> However, I want to make this secure, so I added a function to it which when you log in says if $_SESSION['password'] does not exist then send me away, like so: <?php session_start(); function checklogin() { session_start(); if(!isset($_SESSION['password'])) { header("location: /index/"); exit; } } checkLogin(); Print_r ($_SESSION); echo "Erm, I have reached page.php and the password is ".$_SESSION['password']; ?> However, using the function and a valid log-in it (as shown above) it chucks me out of the page even though $_SESSION['password'] exists? Am I doing something really stupid here? Thank you I am working with a fellow who runs an eCommerce shop. The transaction resolution comes in on a querystring.
I do not yet know what web server software is being used, nor if any security appliance/software is installed.
One of the values in the querystring starts with the @ character.
We know the web server gets this as there entries in the web server's access log that shows thing value is present.
It is not available in PHP's $_GET array.
We are trying to get an idea of where this value, and it's key, is getting discarded.
Is there a known problem with (actual server software being used not yet known) web server software discarding a key/value if the value has the @ character in the querystring?
I am trying to retain information from the $get variable after checking if a user, (Joomla code), is logged in but it is not working. (url: http://domain.com/script.php?file=data) define( '_JEXEC', 1 ); define( 'DS', DIRECTORY_SEPARATOR ); define('JPATH_BASE', '/path/to/joomla/dir/'); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); $mainframe =& JFactory::getApplication('site'); $mainframe->initialise(); $session =& JFactory::getSession(); $user =& JFactory::getUser(); // get username and name of user $username = $user->get('username'); $name = $user->get('name'); if (empty($username)) { die('Not logged in'); } $file = $_GET['file']; echo &file; exit; Any help appreciated. Hi everyone - I am trying to figure out how I can allow my logged in users to leave a php page and go to an html page without losing them as "currently logged in" - I have a site that is mixed with html and php pages and this is what I am needing: i have a user, they are logged in and are visiting a php page. then they want to go to another page(only logged in users can access the php page) - so they click on the html page they want to go to, great! - but then they want to visit another page that is a php page and requires them to be logged in in order to access it. How can i accomplish this without having them log in yet again? is this possible? i am using sessions. Hey all, I am having a situation where I have a singleton class with a static array in it. I insert an element into that array, and then I redirect the user to another page. At that page, I then retrieve that array (it's stored in the session vars), but the array is then empty when I retrieve it. I can't figure out why. Here are some pertinent code snippets. First, the class with the static array: class Logger { private static $instance = NULL; private static $messages = array(); //Private constructor to prevent this class from being instantiated multiple times private function __construct() { } //The clone function is private to prevent cloning of this class private function __clone() { } //Returns the singleton instance of this class public static function GetInstance() { if (!self::$instance) { self::$instance = new Logger; } return self::$instance; } public static function GetMessageCount() { return count(self::$messages); } public static function LogMessage($new_message) { self::$messages[] = $new_message; } public static function GetMessages() { return self::$messages; } public static function ClearMessages() { self::$messages = array(); } } Here is the code where I insert something into the aformentioned array (the process is that a user tries to log in, but the login fails, and so we insert a message into the array saying that the login credentials failed). //Retrieve the message logging instance from the session data to be able to pass messages to the user. $message_log = $_SESSION['user_messages']; $user = $_SESSION['user_account']; //Create a new instance of the database management class and //try to connect to the database $dbm = new DBM(); if ( !$dbm->isConnected() ) { $message_log::LogMessage("We are sorry, but we are unable to access the database at this time. Please try again later."); } else { //Retrieve the user login information $useremail_dirty = $_POST['useremail']; $password_dirty = $_POST['userpassword']; //Check to see if the email we were given exists in the database, and if the password matches $doesPasswordMatch = $dbm->doesPasswordMatch ( $useremail_dirty, $password_dirty ); if ( $doesPasswordMatch ) { //Correct login information was received. Login the user and redirect appropriately. $user->Login(); header ( "Location: ".BASE_URL."/userpage.php" ); exit; } else { //If an incorrect email or password was given, report that information to the user. $message_log::LogMessage("Incorrect login information."); } } //The user has failed to login. Redirect to the appropriate page. header ( "Location: ".BASE_URL."/loginfailed.php" ); And finally, given an unsuccessful login attempt, this is where I pick back up the array of messages to display the messages to the user: $message_log = $_SESSION['user_messages']; $all_messages = $message_log::GetMessages(); print $message_log::GetMessageCount()."<br>"; print count($all_messages)."<br>"; foreach ($all_messages as $message_string) { $prepared_string = prepare_text_for_html_output($message_string); echo $prepared_string."<br>"; } $message_log::ClearMessages(); Unfortunately, the "all_messages" variable has nothing in it...it's like the messages that I logged in the previous PHP script never even existed. I am calling session_start, so don't worry about that (even though it's not seen in these code snippets). What could be going wrong? Hello,
I have a secure login script that uses sessions to maintain a users logged in status. I regenerate the session ID on each page reload for added security. Sometimes, I will lose sessions, and I am hard time figuring out why. It seems to be when I have a slow internet connection. I am wondering what could be causing this?? I have a few ideas, do any of these seem plausible.
-A max execution error, returns a fatal error.
-An ajax request get sent before the previous request returns, so the session ID's dont match an I am kicked out.
Any other ideas would be helpful.
Best,
James
I'm having an issue with holding a session variable in the statement below $Color is losing its value in the if statement. For example int the ( ) $Color is a zero while in the echo part $Color is being displayed correctly as Blue. I have the following code, works rotates the image. But it seems to lose its transparency and add color when rotated to say 45. How can I avoid this? // File and rotation $filename = 'placeholder.png'; $degrees = 45; // Content type header('Content-type: image/png'); // Load $source = imagecreatefrompng($filename); // Rotate $rotate = imagerotate($source, $degrees, 0); // Output imagepng($rotate); ?>
So maybe this is normal, or maybe there is a "better way." The only simple solution appears to be to always save $_POST data to $_SESSION["post"] on the off-chance some visitor some day ever decides to do a $_GET request from a referral link.
3 weeks of my life has been lost to correcting the neverending 'illegal string offset' and 'undefined index' errors etc. by making sure every last variable is declared... Anyway, blah blah blah, that's my rant. Is there a better way? Or is this "how everybody does it?" It seems stupid to have to do all of this.
|