Jump to content

Help, my php keep redirecting


DanePullman

Recommended Posts

I have been following the tutorial betterphp on YouTube on his tutorial on how to make a private message system (PHP Tutorial: Private Message System), but it uses a header {} tag and whenever I use it in Wamp, it loads for a while and eventually says "Connection Timed Out"  "ERR_TOO_MANY_REDIRECTS". I have a link if anyone wants to check my code but I myself, and cannot find any errors. 

 

Private Message System (My Copy - Unfinished) - Download Link:

https://www.dropbox.com/s/rm101g7uhqww7zh/PHP%20Private%20Message%20System.zip?dl=0

 

Video Tutorial - YouTube Link:

https://www.youtube.com/watch?v=5DifzPbAhMU

 

Thanks, Dane

Edited by DanePullman
Link to comment
Share on other sites

Not exactly sure on what bit is causing the error, as im new to php hence why I was following video, but heres code from main file:



<?php
 
$core_path = dirname(_FILE_);
 
if (empty($GET['page']) || in_array("{$GET['page']}.page.inc.php", scandir("{$core_path}/pages")) == false){
header('HTTP/1.1 404 Not Found');
header('Location: index.php?page=inbox');
 
die();
}
 
session_start();
 
mysql_connect('127.0.0.1', 'example_user', 'example_pass');
mysql_select_db('private_message_system');
 
include("{$core_path}/inc/user.inc.php");
 
if (isset($_POST['user_name'], $_POST['user_password'])){
if (($user_id = validate_credentials($_POST['user_name'], $_POST['user_password'])) !== false){
$_SESSION['user_id'] = $user_id;
 
header('Location: index.php?page=inbox');
 
die();
}
}
 
 
if (empty($_SESSION['user_id']) && $_GET['page'] !== 'login'){
header('HTTP/1.1 403 Forbidden');
header('Location: index.php?page=login');
 
die();
}
 
$include_file = "{$core_path}/pages/{$_GET['page']}.page.inc.php";
 
?>

Edited by DanePullman
Link to comment
Share on other sites

You need to be really careful when typing code you see in a video because it's easy to misread something you see. Examples:

if (empty($GET['page'])
$GET is not a thing. This, and the other one, should be $_GET.

$core_path = dirname(_FILE_);
There are supposed to be two underscores on either side.

 

I see some other aspects of the code that are not good, but they won't prevent the code from running so one thing at a time.

 

 

It's great that you want to learn PHP, but the way you're doing it suggests you're just learning how to follow instructions and not how to actually program in the language. I recommend you find a different set of videos for your initial foray into PHP - you can come back to these when you know more about PHP and only need to learn how to do a messaging system itself.

Link to comment
Share on other sites

Fixed the mistakes you said to, just opened in Google Chrome (localhost) and it just returned with this: 

 

( ! ) Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\wamp\www\pk\core\init.inc.php on line 3 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3

 

( ! ) Notice: Undefined variable: GET in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3

 

( ! ) Warning: scandir(./pages,./pages): The system cannot find the file specified. (code: 2) in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.1301 135456 scandir ( ) ...\init.inc.php:5

 

( ! ) Warning: scandir(./pages): failed to open dir: No such file or directory in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.1301 135456 scandir ( ) ...\init.inc.php:5

 

( ! ) Warning: scandir(): (errno 2): No such file or directory in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.1301 135456 scandir ( ) ...\init.inc.php:5

 

( ! ) Warning: in_array() expects parameter 2 to be array, boolean given in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.3704 135584 in_array ( ) ...\init.inc.php:5

 

( ! ) Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\pk\core\init.inc.php:5) in C:\wamp\www\pk\core\init.inc.php on line 6 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.4570 135576 header ( ) ...\init.inc.php:6

 

( ! ) Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\pk\core\init.inc.php:5) in C:\wamp\www\pk\core\init.inc.php on line 7 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.6046 135640 header ( ) ...\init.inc.php:7 ( ! ) Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\wamp\www\pk\core\init.inc.php on line 3 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3
( ! ) Notice: Undefined variable: GET in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3
( ! ) Warning: scandir(./pages,./pages): The system cannot find the file specified. (code: 2) in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.1301 135456 scandir ( ) ...\init.inc.php:5
( ! ) Warning: scandir(./pages): failed to open dir: No such file or directory in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.1301 135456 scandir ( ) ...\init.inc.php:5
( ! ) Warning: scandir(): (errno 2): No such file or directory in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.1301 135456 scandir ( ) ...\init.inc.php:5
( ! ) Warning: in_array() expects parameter 2 to be array, boolean given in C:\wamp\www\pk\core\init.inc.php on line 5 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.3704 135584 in_array ( ) ...\init.inc.php:5
( ! ) Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\pk\core\init.inc.php:5) in C:\wamp\www\pk\core\init.inc.php on line 6 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.4570 135576 header ( ) ...\init.inc.php:6
( ! ) Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\pk\core\init.inc.php:5) in C:\wamp\www\pk\core\init.inc.php on line 7 Call Stack # Time Memory Function Location 1 0.0006 128088 {main}( ) ...\index.php:0 2 0.0011 134952 include( 'C:\wamp\www\pk\core\init.inc.php' ) ...\index.php:3 3 0.6046 135640 header ( ) ...\init.inc.php:7

Edited by DanePullman
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.