Solved

php problem?

Posted on 2016-08-16
5
62 Views
Last Modified: 2016-08-16
I have a very simple php program (attached). It is linked to from another place.

In Firefox, I get the attached jpg.

In Chrome I get a blank screen.

I ran the php syntax through http://phpcodechecker.com/. No issues.

What's wrong?
clear_sess.php
php_issue.jpg
0
Comment
Question by:Richard Korts
  • 3
  • 2
5 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41758209
Please use the code snippet feature to post code samples here at E-E, thanks.
<?php
// clear_sess.php
function conv_date($x) {
		$d = explode("-", $x);
		$r = $d[1] . "/" . $d[2] . "/" . $d[0];
		return $r;
	}
include "db_connect.php";
session_start();
$qry = "SELECT * from users where uid = '" . $_SESSION['uid'] . "'";
$uid = $_SESSION['uid'];
$res = mysqli_query($link, $qry);
$nr = mysqli_num_rows($res);
$u = mysqli_fetch_array($res,MYSQLI_ASSOC);
session_unset();
$_SESSION['uid'] = $u['uid'];
//echo $u['firm_name'] . "<br>";
$_SESSION['firmname'] = $u['firm_name'];
$_SESSION['addr1'] = $u['addr1'];
$_SESSION['addr2'] = $u['addr2'];
$_SESSION['phone'] = $u['phone'];
$_SESSION['tester'] = $u['tester'];
$_SESSION['tg_make_model'] = $u['tg_make_model'];
$_SESSION['tg_sn'] = $u['tg_sn'];
$_SESSION['tg_date_cal'] = conv_date($u['tg_date_cal']);
$_SESSION['city_tester_no'] = $u['city_tester_no'];
if(! empty($_SERVER['HTTP_USER_AGENT'])){
		$useragent = $_SERVER['HTTP_USER_AGENT'];
		if( preg_match('@(iPad|iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-M\d+|Opera Mini|Windows CE|Nokia|SonyEricsson|webOS|PalmOS)@', $useragent) ){
			$loc = "phone.php";
		}
	} else {
	$loc = "form.php";	
	}
header("Location: " . $loc);
exit;
?>

Open in new window

0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41758214
Questions...

1. Did the session start correctly?  How do you know this (either yes or no)?

2. Did the query work?  How do you know this (either yes or no)?

3. What is the purpose of session_unset() on line 15?

4. Was there a reason to not  use session_write_close() in this script?

5. Is there any meaning that we should understand from the comment on line 2?
0
 

Author Comment

by:Richard Korts
ID: 41758232
Ray,

I found the issue; the variable $loc was not set in the non iphone, etc. devices case. Therefore, the header("Location: " . $loc) could not work. Makes PERFECT sense that Chrome displays a blank page.

Because of your questions I put in a bunch of echos, they led me to the solution.

Richard
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41758246
Great!

A "standard" design pattern in almost any programming language is to assign the default variable values before any conditional code block that can change the variable values.  So something like this would be wise...
// SET DEFAULT VALUE TO REDIRECT TO THE HOME PAGE
$loc = '/';

// TEST USER AGENT FOR "PHONE" INDICATORS, CHOOSE REDIRECT PATH
$useragent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : NULL;
if ( preg_match('@(iPad|iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-M\d+|Opera Mini|Windows CE|Nokia|SonyEricsson|webOS|PalmOS)@', $useragent) ) {
    $loc = "phone.php";
} else {
    $loc = "form.php";  
}

// GOTO THE APPROPRIATE SCRIPT LOCATION
header("Location: " . $loc);

Open in new window

0
 

Author Comment

by:Richard Korts
ID: 41758272
That's EXACTLY what I did.

I often do that but not consistently.

R
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Doing something wrong with this PDO Select Statement... 3 18
PHP error function not working on AWS 10 74
selector:validator cookies 4 30
reverse engineer .sql from php files 11 35
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question