Asperon Posted November 16, 2007 Share Posted November 16, 2007 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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/ Share on other sites More sharing options...
teng84 Posted November 16, 2007 Share Posted November 16, 2007 you missed ' header('location : admin_login.php'); Link to comment https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392515 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 sorry that was just an error here, on all of my header('Location:....'); they are set right, sorry for the error, but they don't work (with correct syntax). Link to comment https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392516 Share on other sites More sharing options...
teng84 Posted November 16, 2007 Share Posted November 16, 2007 when you are displaying something then you called header file it wont redirect but it will give you a warning message but if you have turn off error reporting it wont display error warning but it wont redirect Link to comment https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392526 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 is there a reason why it works on my local server but on up online? Link to comment https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392529 Share on other sites More sharing options...
aosmith Posted November 16, 2007 Share Posted November 16, 2007 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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392545 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 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> </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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392549 Share on other sites More sharing options...
aosmith Posted November 16, 2007 Share Posted November 16, 2007 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> </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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392553 Share on other sites More sharing options...
teng84 Posted November 16, 2007 Share Posted November 16, 2007 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> </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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392559 Share on other sites More sharing options...
kenrbnsn Posted November 16, 2007 Share Posted November 16, 2007 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> </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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392561 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 <?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> </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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392569 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 I guess it would be easier to have the admin_login page with the admin page and have all the checks on the one page... but none of my other header functions work anywhere else, so the problem isn't very isolated. Link to comment https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392573 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 if I go straight to admin_login.php and login, and then I go to admin.php, it recognizes the session and runs as it is supposed to, it isjust that darn header() Location function that won't work. Link to comment https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392579 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392586 Share on other sites More sharing options...
premiso Posted November 16, 2007 Share Posted November 16, 2007 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> </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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392592 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392602 Share on other sites More sharing options...
premiso Posted November 16, 2007 Share Posted November 16, 2007 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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392604 Share on other sites More sharing options...
Asperon Posted November 16, 2007 Author Share Posted November 16, 2007 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 https://forums.phpfreaks.com/topic/77545-some-php-issues-im-having/#findComment-392627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.