Jump to content

some php issues I'm having...


Asperon

Recommended Posts

ok, I have a couple things that aren't seeming to work right,

 

on my local apache server my files all work fine, but once I uploaded them a few things went haywire.

 

First:

 

<?php header('Location: admin_login.php'); ?> 

 

the header functions won't work.....would there be a particular reason why?

 

Second:

 

I'm using gd in parts and I use this function to write text

 

<?php ImageTTFText($im,$ln1[2],0,$align,45,$color,$font,$ln1[0]); ?>

 

now, the $font variable was

 

<?php $font =  'c:/windows/fonts/'.$ln1[1].'.ttf'; // $ln1[1] is a font name sent from a form ie arial, times, etc ?>

 

which obviously won't work, becuase of the windows directory, so I copied the fonts I was using and uploaded them, but it still won't

 

work. Obviously browsers recognize fonts because of css, but using the ImageTTFText function, how do I call the fonts I need outside

 

of my local server where I don't have access to my c:/windows/fonts/ directory.

 

Third:

 

Actually...I think that's all for now.. Thank you.

Link to comment
Share on other sites

you should try putting the header command at the very top of your script (or as close as possible)... I had a problem with giving header redirects after the header has already been set, and if you're using html on the same page make sure that code is in the <head> of the doc.

 

Link to comment
Share on other sites

this is what I have

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
</head>
<body>

<?php

session_start();

if(!isset($_SESSION['admin'])){

header('Location: admin_login.php');

}
else
{

$cont = $_GET['cont'];

require('admin_menu.php');

echo "<p>&nbsp</p>";

if(!$cont){

	$require = "admin_bus.php";

	require($require);

}
else{

$require = "admin_".$cont.".php";

require($require);

}

}

?>
</body>
</html>

 

it works when I test it locally with my apache server. but it won't work online.

Link to comment
Share on other sites

give this a whirl:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php

session_start();

if(!isset($_SESSION['admin'])){

header('Location: admin_login.php');

}
else
{

$cont = $_GET['cont'];

require('admin_menu.php');

echo "<p>&nbsp</p>";

if(!$cont){

	$require = "admin_bus.php";

	require($require);

}
else{

$require = "admin_".$cont.".php";

require($require);

}

}

?>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
</head>
<body>
</body>
</html>

 

I had the same problem with the site I'm working on (and actually under very similar circumstances and code ie: works on one server not another)

Link to comment
Share on other sites

session start should always on the top of the page

 

<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php
print_r($_SESSION);
if(!isset($_SESSION['admin'])){
header('Location: admin_login.php');
}
else
{
$cont = $_GET['cont'];
require('admin_menu.php');
echo "<p>&nbsp</p>";
if(!$cont){
	$require = "admin_bus.php";
	require($require);
}
else{
$require = "admin_".$cont.".php";
require($require);
}
}
?>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
</head>
<body>
</body>
</html>

 

try that and tell us what happen

 

Link to comment
Share on other sites

That code shouldn't even work locally. The session_start() must come before anything is sent to the browser. Try this:

<?php
session_start();

if(!isset($_SESSION['admin'])){

header('Location: admin_login.php');

}
else
{

$cont = $_GET['cont'];

require('admin_menu.php');

echo "<p>&nbsp</p>";

if(!$cont){

	$require = "admin_bus.php";

	require($require);

}
else{

$require = "admin_".$cont.".php";

require($require);

}

}

?>
<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
</head>
<body>
</body>
</html>

Link to comment
Share on other sites

<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php
print_r($_SESSION);
if(!isset($_SESSION['admin'])){
header('Location: admin_login.php');
}
else
{
$cont = $_GET['cont'];
require('admin_menu.php');
echo "<p>&nbsp</p>";
if(!$cont){
	$require = "admin_bus.php";
	require($require);
}
else{
$require = "admin_".$cont.".php";
require($require);
}
}
?>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
</head>
<body>
</body>
</html>

 

the output from the print was 'Array()' but the page didn't change

Link to comment
Share on other sites

here is another example

 

<?php
session_start();

if (isset($_POST['userName']) && isset($_POST['password']))
{
$userName = $_POST['userName'];
$password = sha1($_POST['password']);

//connect to database

require("db_connect.php");

$query_userName = "SELECT userName FROM business WHERE userName='$userName'";

$result_userName = mysql_query($query_userName);

$query_password = "SELECT password FROM business WHERE userName='$userName'";

$result_password = mysql_query($query_password);

if(mysql_result($result_userName,0)==$userName && mysql_result($result_password,0)==$password)
{
$_SESSION['validUser'] = $userName;
}

mysql_close($link);
}

?>

<html>
<head>
<title>LOGIN</title>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
</head>
<body>

<?php require_once('menu.php'); ?>

<div class="login">
<br />

<?php

if(isset($_SESSION['validUser']))
{
header("Location: business_view.php");
}
else
{

if(isset($userName)){
echo '<p>Could not log you in</p>';
}
else{
echo '<p>Please login</p>';
}

echo '<form action="business_login.php" method="POST">';
echo '<table>';
echo '<tr>';
echo '<td>User Name</td>';
echo '<td><input type="text" name="userName" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Password</td>';
echo '<td><input type="password" name="password" /></td>';
echo '</tr>';
echo '<tr colspan=2>';
echo '<td><input type="submit" value="LOG IN" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';

}

?>
<br />
<center>
<a href="business_view.php">Account Information</a><br /><a href="password_forgot.htm">Forgot Password?</a>
</center>
<br />


</div>

</body>
</html>

 

locally, the header('Location: business_view.php'); goes to that page and works fine, but online, it doesn't and I have to use the menu to navigate there; it also leaves the page looking incomplete

Link to comment
Share on other sites

That code shouldn't even work locally. The session_start() must come before anything is sent to the browser. Try this:

<?php
session_start();

if(!isset($_SESSION['admin'])){

header('Location: admin_login.php');

}
else
{

$cont = $_GET['cont'];

require('admin_menu.php');

echo "<p>&nbsp</p>";

if(!$cont){

	$require = "admin_bus.php";

	require($require);

}
else{

$require = "admin_".$cont.".php";

require($require);

}

}

$display = '<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="styles/style.css" />
</head>
<body>
</body>
</html>';

echo $display;
?>

 

Did you try that example?

 

That is done right, the issue you are having is that output is being sent to the screen before the header is called, which is why it is throwing the error. A good practice is to keep all the output in a variable and print it later to avoid such hardships as this and even setcookie functions from raising errors as they have to be done before any output is sent to the page.

 

My suggestion would be to store all output (including the output of included files) into a local variable, such as $display that you can just echo out. This way you have full control over what is sent to the page.

 

EDIT:

If you notice all the ones you are trying the header is AFTER output, which is incorrect. I suggest reading up www.php.net/header  on the header() function more before you rip all your hair out over a known issue.

Link to comment
Share on other sites

thanks, I did that, but still nothing... could it be my service providers setup, or what they allow? I've read up on header() I know it shouldn't work the way I had it on my local server but it did, and everything else works online but this...just the header() function...and some gd font issues

Link to comment
Share on other sites

It very well could be. I would contact them, especially of they are a shared hosting and ask. Other than that another option is to do a javascript re-direct instead:

 

echo '<script type="text/javascript">window.location="http://www.server.com/admin_login.php";</script>';

 

As I said, not preferred but it should work, with or without output before the statement.

Link to comment
Share on other sites

I've started using the javascript for the redirects...unhappily, but here is something interesting, this code

 

<?php

session_start();

$act = $_GET['act'];
$ID = $_GET['coupon'];


if(isset($_SESSION['validUser'])){

$username = $_SESSION['validUser'];

require('db_connect.php');

if($act == 'Yes'){

$query = "UPDATE business SET cActive=cActive-1 WHERE username='$username' LIMIT 1";

$result = mysql_query($query) or die('Query failed: '.mysql_error());

$query = "UPDATE coupons SET active='No' WHERE couponID=$ID";

$result = mysql_query($query) or die('Query failed: '.mysql_error());

mysql_close($link);

header('Location: coupon_manage.php');

}

if($act == 'No'){

$query = "SELECT tActive,cActive FROM business WHERE username='$username' LIMIT 1";

$result = mysql_query($query) or die('Query failed: '.mysql_error());

$tActive = mysql_result($result,0,"tActive");

$cActive = mysql_result($result,0,"cActive");

if($cActive < $tActive){

$query = "UPDATE business SET cActive=cActive+1 WHERE username='$username' LIMIT 1";

$result = mysql_query($query) or die('Query failed: '.mysql_error());

$query = "UPDATE coupons SET active='Yes' WHERE couponID=$ID";

$result = mysql_query($query) or die('Query failed: '.mysql_error());

mysql_close($link);

header('Location: coupon_manage.php');

}
else{

mysql_close($link);

header('Location: coupon_manage.php');

}

}

}
else{

echo 'You are not authorized to view this page.';

}

?>

 

goes to a page, makes something active/inactive and goes back to the view page through headers...and it works!....sigh....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.