PHP - Changing Display Resolution
Is it possible to change the client's display resolution using PHP and/or JavaScript?
Thanks Similar TutorialsI have a simple mysql database holding information about an image upload including its 'name' and 'date uploaded' [current_timestamp()] to a folder 'image' I then display it into a table using the php ‘foreach’ facility. I want the date to be displayed in the ‘dd/mm/yyyy’ format. not the default yyyy/mm/dd. Here is the relevant code <?php $conn = mysqli_connect("localhost", "root", "", "dbname"); $results = mysqli_query($conn, "SELECT * FROM tablename"); $image = mysqli_fetch_all($results, MYSQLI_ASSOC); ?> <?php foreach ($image as $user): ?> <td><p>NAME</p><?php echo $user['name']; ?></td> <td><p>COMMENT</p><?php echo $user['comment']; ?></td> <td><p>DATE</p><?php echo $user['date']; ?></td> What do I need to do? THANKS- Warren This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=317879.0 I just started my journey into OOP, just looking for a simple explanation as to why the script echo's nothing. (last line) Code: (php) [Select] <?php class Dog { public $name; public function bark() { echo "{$this->name} says Woof!"; } } class Poodle extends Dog { public function bark() { echo "Yip"; } } $furball = new Poodle; $furball->name = "furball"; $furball->Dog::bark(); ?> If I were to write a code where the browser details and resolution are to be displayed, would the following code work? Code: [Select] //Here, I am using the "</body>" tag to end the body of the webpage and the "</html>" tag to end the HTML script </body> </html> //By using the "<?php" code, I am creating a PHP script and when I use the "function" keyword here, I am creating a function called Identification with no arguments in the parameters <?php function Identification() //Here, I am creating a variable called "$viewer" //The value of this variable uses the "getenv" library function and the "HTTP_USER_AGENT" is what the "getenv" library function will be performed on and the value of this is that value of the $viewer attribute //The code uses the ";" to end the command $viewer = getenv ("HTTP_USER_AGENT"); $width= $_get['width']; $height=$_get['height']; //Here, I am using the "echo" library function and the "$viewer" attribute as well as the "<b> (bold)" tags to write a formatted string to the webpage //I then use the ";" to end the command and I use "?>" to end the PHP script $msg = "Browser details: $viewer"; $msg .= "Resolution is $width pixels long and $height pixels high"; echo ($msg); ?> //Here, I am using the "<html>"<head"> and "<title>" tags as well as the "</head"> and "</title>" so that I can write a title (Browser + Platform Identification Script) for the webpage that the script will be shown on <html><head><title>Browser + Platform Identification Script</title></head> //Here, I am using the "<body>" tag to create the body of the webpage <body> //Here, I am using the "<?php" code so that I can start a PHP script that will run the Identifcation script and show the results on a webpage <?php Identification() //I then use the "}?> to end the PHP script ?> //Here, I am using the "</body>" tag to end the body of the webpage and the "</html>" tag to end the HTML script </body> </html> Thanks, Andrew Hello PHPers, One more help I think may be wrong. I currently have code as $_GET['width'] . "x" . $_GET['height'];. This provides continually with 640 * 480. believe this to be incorrect as I do not think that everyones screen is set to this. Neither is my screen resolution and is still capturing these figures. Is there something wrong with the variable that should be changed so that it can pick up the visitors screen resolution. Thank you kindly, HJ I built a Bootstrap site but when I view it on my phone (Samsung Galaxy S3), it doesn't collapse the navigation menu into the mobile button like I thought it would. I did some research and realized that my phone is actually the same resolution as my desktop (1920x1080) so it's giving me the desktop view. Bootstrap, to my surprise, only seems to be responsive to resolutions, not physical screen sizes. How do I overcome this? I want to build a site which is responsive to physical screen size, regardless of resolution.
Edited by DeX, 11 June 2014 - 04:01 PM. Hey guys, What im trying to do is get the users screen resolution and place it into a database so that i can call it up and place it onto a stats page. So far i get the idea that you have to use Javascript to get the resolution then use PHP to pull that information. What i want to do is pull the screen resolutions and place them into a database so that i can call upon them to place into a stats page So far i have the following getting certain bits of information and banging them into the database using the stats.inc.php then calling them up and placing them onto stats.php. the stats.inc.php is included on every page of my site so it can track where a users has been etc etc. Im assuming i can insert something into my headerLoggedin.inc.php file that will pull the users resolution then use some PHP in the stats.inc.php script to pull that information and then insert it into my database which i can then easily pull from and place into the stats.php page. I know this seems like a bit of a silly thing to be doing, its for a college assignment and im pretty stumped. Any help is appreciated thanks guys. headerLoggedin.php Code: [Select] <?php include('includes/security.inc.php'); ?> <?php include('includes/stats.inc.php');?> <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="en-us" /> <link rel="stylesheet" href="css/index.css" type="text/css"/> <title>############</title> </head> <body> <!-- Start of wrapper div--> <div id="wrapper"> <!-- Start of header div--> <div id="header"> <div id="logo"><img src="./images/logo.png" width="412" height="32" alt="Elite Recruitment Services" /></div> <div id="navigation"> <ul class="nav"> <li><a href="news.php">News Page</a></li> <li><a href="edit.php">Edit text file</a></li> <li><a href="upload.php">Upload text file</a></li> <li><a href="stats.php">Stats</a></li> <li><a href="logout.php">Logout</a></li> </ul> </div> </div> <!--End of header div--> <!--Start of loginContainer div--> <div id="formsContainer"> stats.inc.php Code: [Select] <?php $db_host = "localhost"; // Databases host name $db_username ="#######"; // Database Username $db_password ="#######"; // Database Password $db_name ="dannymit_stats"; // Databases name $db_table="statTracker"; // Database table where the logins are stored mysql_connect("$db_host", "$db_username", "$db_password"); // Connects to the database using the preset host, username and password mysql_select_db("$db_name"); // Selects the database. //collect information... $browser = $_SERVER['HTTP_USER_AGENT']; // get the browser name $curr_page = $_SERVER['PHP_SELF'];// get page name $ip = $_SERVER['REMOTE_ADDR']; // get the IP address $from_page = $_SERVER['HTTP_REFERER'];// page from which visitor came $page = $_SERVER['PHP_SELF'];//get current page $width = $_GET['width']; //Gets users screen width $height = $_GET[['height']; //Gets users screen height //Insert the data in the table... $query_insert = "INSERT INTO statTracker (browser,ip,thedate_visited,page,from_page) VALUES ('$browser','$ip',now(),'$page','$from_page')" ; $result=mysql_query ( $query_insert); if(!$result){ die(mysql_error()); } ?> stats.php Code: [Select] <?php // Header include include('includes/headerLoggedin.inc.php'); include('includes/stats.inc.php'); ?> <br/><br/> <?php $db_host = "localhost"; // Databases host name $db_username ="######"; // Database Username $db_password ="######"; // Database Password $db_name ="dannymit_stats"; // Databases name $db_table="statTracker"; // Database table where the logins are stored mysql_connect("$db_host", "$db_username", "$db_password"); // Connects to the database using the preset host, username and password mysql_select_db("$db_name"); // Selects the database. $sqlquery = "SELECT * FROM `$db_table`"; $result = mysql_query($sqlquery); $num = mysql_num_rows($result); mysql_close(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf ("Browser:<br/> %s<br/> IP Address:<br/> %s<br/> Date Visited:<br/> %s<br/> Page Visited:<br/> %s<br/> Paged Visited From:<br/> %s<br/>", $row[1], $row[2], $row[3], $row[4], $row[5]); echo "<br />"; } ?> <?php include('includes/footer.inc.php');?> I have two css external style sheets. One for the 800x600 screen resolution and other for 1200x768. How can I detect the screen resolution and apply the according style sheet using PHP. If I use Javascript, It is possible that the Javascript may not be enable on client side. has some one a better solution? i am creating a responsive website.
I'll give you an example.
I am retriving 100 items from mysql database using php. I am only showing 20 items per page using simple pagination with arrows. I keep this format on desktop and tablets. However, I would like to show less items when I am viewing the page on a smartphone. So instead of 20 items per page, it'll show 5 items per page along with the pagination arrows.
I was wondering if this is possible with PHP or would I have to use javascript?
Hi, I am changing my ISP and need to import my databases.
Do I I have to create a new datarbase or can I change my database name to import?
My new host has a different database prefix ie: -web147xxxxxxxx
My old one was arewene1_wor1.
Many thanks.
As I am VERY new to PDO, can someone help me in converting the below 2 codes so that I can setup the testing site knowing at least this part works. Below is the old SQL that I need to convert but don't have to foggiest on where to start. If I can get some help with this I can slowly work through the rest of my site with a bit more ease. LOGIN CODE: <?php if($_POST['submit']){ $Username = protect($_POST['Username']); $Password = protect(sha1($_POST['Password'])); if(!$Username || !$Password){ echo "<center>Please enter your <b>Username</b> and <b>Password</b>!</center>"; }else{ $res = mysql_query("SELECT * FROM `eusers` WHERE `Username` = '".$Username."'"); $num = mysql_num_rows($res); if($num == 0){ echo "<center>The <b>Username</b> or <b>Password</b> you supplied is incorrect!</center>"; }else{ $res = mysql_query("SELECT * FROM `eusers` WHERE `Username` = '".$Username."' AND Password = '".$Password."'"); $num = mysql_num_rows($res); if($num == 0){ echo "<center>The <b>Password</b> you supplied is incorrect!</center>"; }else{ $row = mysql_fetch_assoc($res); if($row['Active'] != 1){ echo "<center>Your login has been <b>deactivated</b>, Please contact your Manager for assistance.</center>"; }else{ header('Location: secure.php'); $time = date('U')+7200; //2 Hours mysql_query("UPDATE `eusers` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); $_SESSION['uid'] = $row['id']; }}}}} ?> ACCESS GRANTED (Each Page): <?php if(strcmp($_SESSION['uid'],"") == 0){ printf("<script>location.href='index.php'</script>"); }else{ $time = date('U')+7200; //2 Hours $update = mysql_query("UPDATE `eusers` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); } ?>
// SESSION TEST if ($_SESSION['username']) { require_once("../mysql.php"); // Find Username from Session ID // Find Username from ID $finduser="SELECT username FROM users WHERE id='$_SESSION[username];'"; $finduserquery=mysql_query($finduser)or die(mysql_error()); $userfetch = mysql_fetch_array($finduserquery); // Set Username Variable $userfromid = $userfetch['username']; echo "lol" . ucwords($userfromid); } else { } Everytime I load this page more than once when logged in, it seems to turn the variable blank. Therefore making the user not be able to view other pages that use a session. Help? Thanks Hey folks, I have made a cart. My output of the cart ( when I receive a mail of the order ) is like this "3,2,4,2" ,, the numbers are the id's of the items, but instread of the id's of the items, I would like to have the names of the items as an output in mail.php, column in sql table is also 'name' what should I do ?? the cart http://fhcs.be/cart-demo4/ thanks in advance index.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session require_once('mail.php'); session_start(); ?><!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" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo &#0183; Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Welkom, plaats uw order</h1> </div> <div id="booklist"> <h1>Warme dranken</h1> <?php $sql = 'SELECT * FROM products WHERE cat=2'; $result1 = $db->query($sql); $output1[] = '<ul>'; while ($row = $result1->fetch()) { $output1[] = '<li>'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output1[] = '</ul>'; echo join('',$output1); ?> <h1>Cocktails</h1> <?php $sql = 'SELECT * FROM products WHERE cat=3'; $result2 = $db->query($sql); $output2[] = '<ul>'; while ($row = $result2->fetch()) { $output2[] = '<li>'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output2[] = '</ul>'; echo join('',$output2); ?> </div> </body> </html> mail.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); session_start(); if($_POST['sendemail'] == 'Email') { $info =($_POST['cart']); $headers = 'From: Sender <from@fhcs.be>'; mail('to@fhcs.be', 'Subject', $info, $headers); echo $_POST["cart"]; echo 'Your mail has been sent'; } else { echo 'Your mail was not sent'; } ?> cart.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$name.'</td>'; $output[] = '<td>€'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>€'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>€'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> functions.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$name.'</td>'; $output[] = '<td>€'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>€'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>€'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> Any chance you could help me out with some probably simple code ? I need to change an image when the script change state. So instead of $Streamstatus "off"or "on" I would like to change an image. Cheers Code: [Select] <?php $request = 'http://api.own3d.tv/liveCheck.php?live_id='; $arg = 'Zerkilive'; $session = curl_init($request.$arg); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); if (preg_match("/true/",$response, $result)) { $streamStatus="on"; $color="green"; } else { $streamStatus="off"; $color="red"; } echo $streamStatus; ?> Hi, I've got the follow array: Query: Code: [Select] SELECT concat(monthname(gl_date),", ",year(gl_date)) as "monthYear", concat(DATE_FORMAT(gl_date,"%d-%m-%Y"),", ",gl_venue) as "dateVenue", DATE_FORMAT(gl_date,"%d-%m-%Y")as "date", gl_venue as "venue", gl_city as "city", gl_postcode as "postcode", gl_text as "description", concat(DAYOFMONTH(gl_date), MONTHNAME(gl_date),".png") AS "imageName" FROM tg_gig_list where gl_date >= curdate() and gl_publish = 1 order by gl_date Array: Code: [Select] $array = array(); $array['gigs'] = array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $array['gigs'][] =$row; } $output = json_encode($array); This returns JSON like this: - Code: [Select] { "gigs": [ { "monthYear": "May, 2011", "dateVenue": "14-05-2011, Queen Victoria hall", "date": "14-05-2011", "venue": "Queen Victoria hall", "city": "Oundle", "postcode": "PE8 4EJ", "description": "", "imageName": "14May.png" }, { "monthYear": "May, 2011", "dateVenue": "19-05-2011, O'Neill's", "date": "19-05-2011", "venue": "O'Neill's", "city": "Peterborough", "postcode": "PE1 1SQ", "description": "This one is another outing for Jason and Darren's acoustic duo, the pair will be playing a selection of their favourite songs as well as some tunes from the guards set.<br \/>\r\n<br \/>\r\n19:00 to 21:00", "imageName": "19May.png" }, {.......next record I'd like the data to be arranged by the 'monthYear' field....something like this... Code: [Select] { "gigs": [ "monthYear": "May, 2011" { "monthYear": "May, 2011", "dateVenue": "14-05-2011, Queen Victoria hall", "date": "14-05-2011", "venue": "Queen Victoria hall", "city": "Oundle", "postcode": "PE8 4EJ", "description": "", "imageName": "14May.png" }, {......all gigs for 'May, 2011' } "monthYear": "June, 2011" {....records for 'June, 2011' so 'gigs'=>'monthYear'=>'other records' I've tried all sorts of combinations of putting the '$row['monthYear']' field in different places in the array, but I seem to loose data by doing so for some reason. any input greatly appreciated. Darren Hi, I'm using the following code: <td>$row[color]</td> and the possible values for this field are 1, 2 and 3. But I want the return to be red for 1, blue for 2, and green for 3. How do I write it so that instead of getting a row of 1's, 2's and 3's, I change those numbers to their corresponding colors? Thanks! Hi Guys, I have a list of branches in a database table with the following collumns, Ter BranchName BranchAddress BranchTel BranchEmail BranchLink Ter = Terriotory ID However every time i update a branch using the edit.php code it always sets the Ter as 1 again! Rather than leaving it the same. The actual field is read-only to prevent that from happening. It then always comes up with the error Duplicate entry '1' for key 1 but thats because there is already a branch with Ter=1 include('config.php'); if (isset($_GET['Ter']) ) { $ter = (int) $_GET['Ter']; if (isset($_POST['submitted'])) { foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } $sql = "UPDATE `ter` SET `Ter` = `BranchName` = '{$_POST['BranchName']}' , `BranchAddress` = '{$_POST['BranchAddress']}' , `BranchTel` = '{$_POST['BranchTel']}' , `BranchEmail` = '{$_POST['BranchEmail']}' , `BranchLink` = '{$_POST['BranchLink']}' WHERE `Ter` = '$ter' "; mysql_query($sql) or die(mysql_error()); echo (mysql_affected_rows()) ? "Edited Branch.<br />" : "Nothing changed. <br />"; } $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' ")); <form action='' method='POST'> <p><b>Territory:</b><br /><input name='Ter' type='text' value='<?= stripslashes($row['Ter']) ?>' size="3" readonly="readonly" /> <p><b>Branch Name:</b><br /><input name='BranchName' type='text' value='<?= stripslashes($row['BranchName']) ?>' size="50" /> <p><b>Address:</b><br /> <textarea name="BranchAddress" cols="40" rows="5"><?= stripslashes($row['BranchAddress']) ?></textarea> <p><b>Telephone:</b><br /><input name='BranchTel' type='text' value='<?= stripslashes($row['BranchTel']) ?>' size="15" /> <p><b>Email:</b><br /><input name='BranchEmail' type='text' value='<?= stripslashes($row['BranchEmail']) ?>' size="50" /> <p><b>Link:</b><br /><input name='BranchLink' type='text' value='<?= stripslashes($row['BranchLink']) ?>' size="50" /> <p><input type='submit' value='Save' /><input type='hidden' value='1' name='submitted' /> </form> <? } ?> Any Ideas? Cheers, S okay i need help with this part of code i need to set time 00:00 to 24:00 Code: [Select] $vrijeme_otvoreno = "$rv_od_h:$rv_od_min"; $vrijeme_zatvoreno = "$rv_do_h:$rv_do_min"; if ($vrijeme_otvoreno =="00:00" && $vrijeme_zatvoreno == "00:00") { $vrijme_zatvoreno = "24:00"; echo $vrijeme_zatvoreno; } echo "$vrijeme_otvoreno - $vrijeme_zatvoreno <br>"; i get echo 00:00 - 00:00 and i need it to be 00:00 - 24:00 Salting passwords... How can you update the salting without getting all the users to change their password? Is the salting set in stone once created? |