10 Replies - 1034 Views - Last Post: 09 October 2012 - 10:23 PM Rate Topic: -----

#1 machorong  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 05-October 12

alert box in php

Posted 09 October 2012 - 06:19 AM

Hello I just want to know how to change this to a alert box



<?php
 include 'core/init.php';
include 'includes/overall/indexOver.php';

if (empty($_POST) === false){
	$username = $_POST['username'];
	$password = $_POST['password'];	
		
		 
	
	if(empty($username) === true || empty($password) === true) {
		$errors = 'you need to enter username or password';
	} else if(user_exists($username) === false){
		$errors= 'We can\'t find the username. Have you registered?';
	}	else if(user_active($username)=== false)	{
		$errors = 'please activate your account';
	}else{
	$login = login($username, $password);
			if($login === false){
				$errors[] = 'your username or password is incorrect';
			}else{
			
				$_SESSION['id'] = $login;
				header('Location: main1.php');
				exit();
			}
	}
	


	print_r($errors);
	
	
}
?>



Is This A Good Question/Topic? 0
  • +

Replies To: alert box in php

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3521
  • View blog
  • Posts: 10,162
  • Joined: 08-June 10

Re: alert box in php

Posted 09 October 2012 - 06:38 AM

if you mean something like Javascriptís window.alert() then there is bad news, there is no such thing in PHP.

however you could print out some Javascript code that does exactly that.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,062
  • Joined: 10-May 07

Re: alert box in php

Posted 09 October 2012 - 06:40 AM

You could use the Twitter Bootstrap alert, & feed it server side messages in php. However the act of opening an alert box (styled or not) is going to be handled by the browser, which is a client side execution & not server side. Thus to 2nd what Dormilich said, php isn't the tool for this.
Was This Post Helpful? 0
  • +
  • -

#4 machorong  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 05-October 12

Re: alert box in php

Posted 09 October 2012 - 06:57 AM

@Dormilich- is that so can you help how to do that
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3521
  • View blog
  • Posts: 10,162
  • Joined: 08-June 10

Re: alert box in php

Posted 09 October 2012 - 07:13 AM

I can aid in the process, but Iím certainly not writing it for you (which would be a major rewrite anyways).
Was This Post Helpful? 0
  • +
  • -

#6 machorong  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 05-October 12

Re: alert box in php

Posted 09 October 2012 - 07:24 AM

so you mean I need to change all of this just to put the alert box that I wanted

well anyway that's cool for me
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3521
  • View blog
  • Posts: 10,162
  • Joined: 08-June 10

Re: alert box in php

Posted 09 October 2012 - 07:25 AM

first you need to decide the output format of it all. currently you have text (output) disguised as HTML (default response header) ...
Was This Post Helpful? 0
  • +
  • -

#8 machorong  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 05-October 12

Re: alert box in php

Posted 09 October 2012 - 08:08 AM

Yo I got it

<?php
 include 'core/init.php';
include 'includes/overall/indexOver.php';

if (empty($_POST) === false){
	$username = $_POST['username'];
	$password = $_POST['password'];	
		
		 
	
	if(empty($username) === true || empty($password) === true) {
		//$errors = 'you need to enter username or password';
		echo "<script>alert(\"you need to enter username or password!\");</script>";
	} else if(user_exists($username) === false){
		//$errors= 'We can\'t find the username. Have you registered?';
		echo "<script>alert(\"We can\'t find the username. Have you registered?\");</script>";
	}	else if(user_active($username)=== false)	{
		$errors = 'please activate your account';
	}else{
	$login = login($username, $password);
			if($login === false){
				//$errors[] = 'your username or password is incorrect';
				echo "<script>alert(\"your username or password is incorrect?\");</script>";
			}else{
			
				$_SESSION['id'] = $login;
				header('Location: main1.php');
				exit();
			}
	}
	


	//print_r($errors);
	
	
}
?>

 





Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3521
  • View blog
  • Posts: 10,162
  • Joined: 08-June 10

Re: alert box in php

Posted 09 October 2012 - 10:05 AM

four comments.

- you are aware that this output is nowhere close to a proper HTML document?

- it does not work with Javascript disabled.

- why use header() when you can use include()?

- telling the user that his password resp. login is wrong gives attackers more information than is good for you1). better tell the user that the password-login combination (but not which one) is wrong.


1) if an attacker gains a valid password, finding the appropriate username is only a matter of time.
Was This Post Helpful? 1
  • +
  • -

#10 machorong  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 05-October 12

Re: alert box in php

Posted 09 October 2012 - 07:43 PM

We're only needing this for our project this will not go online
Was This Post Helpful? -1
  • +
  • -

#11 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3521
  • View blog
  • Posts: 10,162
  • Joined: 08-June 10

Re: alert box in php

Posted 09 October 2012 - 10:23 PM

that doesnít matter. a project is there to train you for the real thing. and if you only ever made projects where security and efficiency didnít matter, I can bet that the real life project then has more security holes than you can count.
Was This Post Helpful? 4
  • +
  • -

Page 1 of 1