PHP website working on Localhost but not working on Server or cPanel

I have been battling with this the Code for days now and i am stuck. i host the PHP files on my localhost and it works very perfectly but once uploaded on a Server/Cpanel i just get errors, i have tried editing and editing the code and all but it never redirects to what i want.

Please someone help me.

It starts with a Login PAGE (INDEX.PHP) and should pass through another page (LOGAUTH.PHP) and automatically redirects you to (PG.php)

But once i put the username details on the INDEX.php and click Next … it shows me this error from LOGAUTH.php

Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/html/hszgroup.com/www.hszgroup.com/upload/attachment//fedhs/logauth.php:6) in /home/httpd/html/hszgroup.com/www.hszgroup.com/upload/attachment/fedhs/logauth.php on line 8

LINE 8 IS BELOW:

:if(preg_match("/[a-z0-9.%±]+@[a-z0-9.-]+.[a-z]{2,}$/",strtolower($email)) || preg_match("/[0-9]{6,15}$/",$email) || preg_match("/[a-zA-Z][a-zA-Z0-9.-_]{5,31}/",$email)){$_SESSION[‘email’] = $email;header(‘location:pg’);}

It’s the output started at line 6, that’s preventing the header() from working. what are the first 6 lines of code in the file?

<?php
session_start();
include "antibots.php";
include "config.php";

LINE 6: if(isset($_POST['1sty'])){echo $email;

NOTE: IT WORKS PERFECTLY ON LOCALHOST WAMP SERVER

Line 6 is echoing the $email variable, producing output. you cannot output anything, then use a header() statement.

The reason this works on your localhost development system is because php has made a large number of bad decisions in its history, that hurt beginning programmers. One of which is to have an output_buffering setting, which when turned on, allows you to output things before a header() statement, but which your live server has set to off. I recommend that you edit the php.ini on your development system and set output_buffering to OFF, so that code you develop has a chance of working when you move it to a live server.

Your code implies you have form processing code and form on two separate pages, requiring a lot of extra code to make it work. The form processing code and form should be on the same page. The code for any page should be laid out in this general order -

  1. initialization
  2. post method form processing
  3. get method business logic - get/produce the data needed to display the page
  4. html document

Thank you so much, i am working on that right now and will give you feedback

I just checked my php.ini file on my wamp localhost and this was the result for output buffering

; output_buffering
; Default Value: Off
; Development Value: 4096
; Production Value: 4096

When i changed the Default Value to On. The error started.

I really have to idea how to edit the code to make it work

That is a block of comments showing suggested values. The actual setting doesn’t start with a ;

okay. i got it . thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service