Jump to content

[SOLVED] 500 Server Error When Sending Certain Post or Get Data.


jjacquay712

Recommended Posts

The 500 errors on php pages are usually caused by php errors that prevent the code from completing.

 

You would need to check your web server error log and/or post your code if you want someone to help determine what it might be doing that would cause such an error when data containing http:// is received.

Link to comment
Share on other sites

I was looking at the Apache logs and it doesnt say anything specific about the error.

 

Here is the code im using:

 

<?php
require("db_config.php");
session_start();

if ( $_SESSION['username'] ) {
$title = "Create Link";
require("includes/page_top.php");
if ( $_GET['page'] ) {
	if ( $_POST['Submit'] ) {
		if ( $_POST['title'] && $_POST['url'] ) {
			mysql_query("INSERT INTO `links` (`main` ,`title` ,`url`) VALUES ('{$_GET['page']}', '{$_POST['title']}', '{$_POST['url']}');");
			if ( $_GET['refer'] ) {
				echo '<h1>Link Created</h1><p><input type="button" value="Back" onClick="document.location=\'http://' . $_GET['refer'] . '\';"></p>';
			} else {
				echo '<h1>Link Created</h1><p><input type="button" value="Back" onClick="document.location=\'create_link.php\';"></p>';
			}
		} else {
			echo '<p style="color: red;">Please Fill Out All Fields</p>';
			include("includes/create_link_form.php");
		}
	} else {
		include("includes/create_link_form.php");
	}
} else {
	echo '<h1>Create Link</h1><br />';
	echo '<table><tr class="fieldname"><td>Name</td><td></td></tr>';
	$alter = "white";
	$query = mysql_query("SELECT * FROM pages WHERE owner = '{$_SESSION['username']}'");
	while ( $page = mysql_fetch_array($query) ) {
		if ($alter == "white") {
			echo '<tr class="' . $alter . '">';
			$alter = "black"; 
		} else {
			echo '<tr class="' . $alter . '">';
			$alter = "white";
		}
		echo '<td>' . $page['name'] . '</td><td><a href="create_link.php?page=' . $page['id'] . '" class="delete" title="Create Link"><img src="images/add.png" /></a></td></tr>';	  
	}
	echo '</table>';
}
require("includes/page_bottom.php");
} else {
header("location: index.php");
}
?>

 

It's basically a a form on my CMS that allows you to add a link to the page.

Link to comment
Share on other sites

Which exact variable is the one that ends up with the http:// in it and does the problem occur for any value with http:// or only for specific url's?

 

And, you need to use mysql_real_escape_string() on all external data that is put into a query.

Link to comment
Share on other sites

$_POST['url'] is the variable that has the http:// in it. I also have a sanitize function already in use in db_config.php that loops through each of the $_POST vars.

 

<?php
function sanitize($input) {
if ( is_array($input) ) {
	foreach ( $input as $title=>$data ) {
		$input[$title] = mysql_real_escape_string($data);
	}	
	return $input;
} else {
	return mysql_real_escape_string($input);	
}
}

$_POST = sanitize($_POST);
$_GET = sanitize($_GET);
?>

 

EDIT:

 

It occurs with any POST or GET data being sent.

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.