Jump to content

Recommended Posts

Hello,

For a school project we have made a very simple Jquery mobile website. In this website you can create "Quick Links" that will put them in a list for you. The website is running and is doing good. However, there is one tiny problem. After you have added a link we made it that you will be redirected to the main page using the code:

 

if($result){
  header("location: /index.php/");

 

This works great, but it will keep the /voegtoe.php in the url when you are at the index.php which results in you not being able to click anything because the systsem is confused. Does anyone have any solutions that will resolve this and just redirect it so that the user will go to index.php?

 

Thanks in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/275843-header-location/
Share on other sites

<?php 
		if (isset($_POST['submit'])){
			$name = $_POST['name'];
			$url = $_POST['url'];
			if($name == "" || $url == ""){
				echo "Vul a.u.b. alle velden in.";
			}else{
				$sql = "INSERT INTO links SET url_name='".$name."', url='".$url."'";
				$result = mysql_query($sql);
				if($result){
					header("location: /index.php/");
				}else{
					echo "Uw link is niet opgeslagen, probeer het opnieuw.";
				}
			}
		}
		
		?>

 

Yeah that uses the same code for the redirect.

Link to comment
https://forums.phpfreaks.com/topic/275843-header-location/#findComment-1419493
Share on other sites

Can't say I see anything wrong with it... the redirect at least. However, I would use something like this:

 

if($result){
header("Location: /index.php");
  exit();

I dont know if it makes a difference, but I dont see why you shouldnt give it a shot.

 

On a side note....

For security sake, dont ever use a variable in a query without at least validating it. You can read more about validation on php.net, look into mysql_real_escape_string() as well as htmlentities(), like such:

 

 

$name = mysql_real_escape_string(htmlentities($_POST['name']));
$url = mysql_real_escape_string(htmlentities($_POST['url']));
Edited by DaveyK
Link to comment
https://forums.phpfreaks.com/topic/275843-header-location/#findComment-1419496
Share on other sites

Also, I would just like to point out that input validation doesn't necessarily help against SQL injections. For that you have to use the proper output escaping method, which is either *real_escape_string () or Prepared Statements. I recommend the latter, using the PDO or MySQLI libraries, as that handles the escaping for you.

 

Secondly: htmlspecialchars and htmlentities should never be used prior to adding data to the database. They are HTML escaping functions, which means that you should only use them immediately before sending content to the browser. Also, htmlentities escapes far more than necessary for HTML, and as such htmlspecialchars is the one you should use.

 

The correct order of processing data from a user is as follows:

  • Validate data.
  • Show validation errors, if necessary.
  • Process the data (business logic).
  • Escape and send to the correct third party system (browser or database, most likely).
Link to comment
https://forums.phpfreaks.com/topic/275843-header-location/#findComment-1419524
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.