Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing session id width JS not working

Status
Not open for further replies.

renzocj

Programmer
Sep 1, 2011
8
PE
In order to pass a session Id using the URL

This works fine:

Code:
<h1 id="goHome"><a href="home.php?<?php echo htmlspecialchars(SID); ?>">Inicio</a></h1>

The h1 tags are inside little divs like buttoms, so the divs are links to home.php to:

Code:
function myMenu() {
olinkA=document.getElementById("goHome");
//add event...
addEvent(oLinkA,'click',goNow);
}


//this does not work
//the home.php has no session at all
function goNow() {
location.href="home.php?<?php echo htmlspecialchars(SID); ?>";
}

Any idea ? how can I send the session ID to the next page using Javascript as a link sender (location.href) ?

Thanks
 
You don't need to, start the session on the next page and will have the same session id.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I already did but my browser apparently does not allow cookies, so I wanted to have a second way to establish the session.

LOGIN PAGE:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<?php
session_start();

include_once('overall.php');

if (isset($_POST['mail_log']) && isset($_POST['pass_log'])) {
	//if the user has just tried to log in
	$email=$_POST['mail_log'];
	$password=$_POST['pass_log'];
	
	$db_conn=new mysqli('***', '***', '***', '***');
	
	if (mysqli_connect_errno()) {
		echo '<h1>No se realizó una conexión a base</h1>';
		exit;
	}
	
	$query='select * from authorized_users '."where name='$email' "." and password=sha1('$password')";
	
	$result=$db_conn->query($query);
	 
	if ($result->num_rows) {
		//if they are in the database register the user id
		$_SESSION['valid_user']=$email;
	}
	$db_conn->close();

}

?>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>...

In other part of the page...

Code:
<div id="login_area">
            <?php
			
			create_heading();
			
			?>
            </div><!--login_area-->

create_heading function:

Code:
//this function say hello to the registerd member or if not creates a form to registe new member.

AS THE SECOND PAGE.............

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<?php
session_start();

include('overall.php');

?>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>...

In other part of the page:

Code:
<div id="login_area">
            <?php
			
			create_heading();
			
			?>
            </div><!--login_area-->

This function must say hello to the member, however if you log in the page number one, here the session is not active, this is why I wanted to create the sessions using URLs too...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top