Login Problem !

Programovacie jazyky, rady, poradňa...
Axcel
Novice
Novice
Príspevky: 9
Registrovaný: 24 júl 2009, 18:06
Kontaktovať používateľa:

Login Problem !

Príspevok od používateľa Axcel »

Problem je v tom ze po prihlaseni na stranku sa chcem dostat napr. do contact.php, ale ked kliknem na odkaz http://mojadomena.sk/contact.php tak na tej stranke uz nie som Prihlaseni ! Preco ?!
audiotrack
VIP
VIP
Používateľov profilový obrázok
Príspevky: 25958
Registrovaný: 09 sep 2005, 18:39
Kontaktovať používateľa:

Príspevok od používateľa audiotrack »

lebo tam nemáš inicializované session? Môžeme len hádať bez zdrojákov. Skús ale písať ako človek, netreba farebne a hrubým
Axcel
Novice
Novice
Príspevky: 9
Registrovaný: 24 júl 2009, 18:06
Kontaktovať používateľa:

Zdrojaki :

Príspevok od používateľa Axcel »

Tu mas Zdrojaki :

Tu ti dam zdrojovi kod formulara : form.php

Kód: Vybrať všetko

<form method="post" action="login.php">
<label for="username">Username: </label><br />
<input type="text" name="username" id="username"><br />
<label for="password">Password: </label><br />
<input type="password" name="password" id="password"><br />
<input type="submit" name="submit" id="submit" value="Submit">
</form>
a tu mas login.php

Kód: Vybrať všetko

<?php 
include("config.php");
 
// Start a session. Session is explained below.
session_start();
 
// Same checking stuff all over again.
if(isset($_POST['submit'])) {
	if(empty($_POST['username']) || empty($_POST['password'])) {
		echo "Sorry, you have to fill in all forms";
                exit;
	}
	// Create the variables again.
	$username = $_POST['username'];
	$password = $_POST['password'];
	// Encrypt the password again with the md5 hash. 
	// This way the password is now the same as the password inside the database.
	$password = md5($password);
 
	// Store the SQL query inside a variable. 
	// ONLY the username you have filled in is retrieved from the database.
	$query = "SELECT username,password 
			  FROM	 `users`
			  WHERE	 username='$username'";
 
	$result = mysql_query($query);
	if(!$result) { 
		// Gives an error if the username given does not exist.
		// or if something else is wrong.
		echo "The query failed " . mysql_error();
	} else {
		// Now create an object from the data you've retrieved.
		$row = mysql_fetch_object($result);
		// You've now created an object containing the data.
		// You can call data by using -> after $row.
		// For example now the password is checked if they're equal.
		if($row->password != $password) {
			echo "Zadali ste zle heslo.";
                        exit;
		}
		// By storing data inside the $_SESSION superglobal,
		// you stay logged in until you close your browser.
		$_SESSION['username'] = $username;
		$_SESSION['sid'] = session_id(); 
		// Make it more secure by storing the user's IP address.
		$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
		// Now give the success message.
		// $_SESSION['username'] should print out your username.
		echo "Prihlasili ste sa uspesne" . $_SESSION['username'];
	}
}
?>
Dufam ze som ti dal potrebne info abi si mi pomohol !!
audiotrack
VIP
VIP
Používateľov profilový obrázok
Príspevky: 25958
Registrovaný: 09 sep 2005, 18:39
Kontaktovať používateľa:

Príspevok od používateľa audiotrack »

v podstate ani nie, ale aj tak si myslím že som problém uhádol hneď na začiatku. :) na každú stránku daj

Kód: Vybrať všetko

<?php session_start(); ?>
hneď do prvého riadku, pred akýkoľvek kod
Axcel
Novice
Novice
Príspevky: 9
Registrovaný: 24 júl 2009, 18:06
Kontaktovať používateľa:

Thanx !

Príspevok od používateľa Axcel »

THX za pomoc idem to viskushat !
Napísať odpoveď