Could anybody please help me???

Any problem with PHP can be disscused here
Praveen
Posts: 146
Joined: Fri Oct 21, 2005 11:47 am
Contact:

Could anybody please help me???

Post by Praveen »

Hi

I know asp to some extent and php nothing. I want a session script in php. Could anybody help me?

In ASP the code works like this.

Code: Select all

<%
Session("session_name") = "123"
%>

<%
If Session("session_name") = "123" Then
%>
Execute these HTML codes.
<%
Else
%>
Execute these false HTML codes.
<%
End If
%>
I want a code in php. Please help.

Edited by moderator. For code use code tags !!


Image
johnjg75
Posts: 108
Joined: Thu Nov 03, 2005 2:31 am

Post by johnjg75 »

Code: Select all

<?php
session_start();
$sessionname = "123";
session_register('sessionname');
?>

<?php
if($_SESSION[sessionname] = "123")
{
?>
Execute these HTML codes.
<?php
}else{
?>
Execute these false HTML codes.
<?php
}
?>
That's my closest guess, i haven't used PHP in awhile.

Edited by moderator. For code use code tags !!
UNDERCOVER
Posts: 115
Joined: Tue Apr 05, 2005 1:02 pm

Post by UNDERCOVER »

read this to understand how it works http://au2.php.net/function.session-start
johnjg75
Posts: 108
Joined: Thu Nov 03, 2005 2:31 am

Post by johnjg75 »

that looks fairly close to mine, right?
Praveen
Posts: 146
Joined: Fri Oct 21, 2005 11:47 am
Contact:

Post by Praveen »

Thaaaaaaaaaaaaaaaaaaaanks a lot!
Image
Praveen
Posts: 146
Joined: Fri Oct 21, 2005 11:47 am
Contact:

Post by Praveen »

But I have a little problem.
Iam getting the error:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at c:\Inetpub\www\Workings\55psd\index.php:4) in c:\Inetpub\www\Workings\55psd\index.php on line 80

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at c:\Inetpub\www\Workings\55psd\index.php:4) in c:\Inetpub\www\Workings\55psd\index.php on line 80

Notice: Use of undefined constant sessionname - assumed 'sessionname' in c:\Inetpub\www\Workings\55psd\index.php on line 85
Edited by moderator. For errors use quote tags !!
Image
Praveen
Posts: 146
Joined: Fri Oct 21, 2005 11:47 am
Contact:

Post by Praveen »

If you can please remodify this in php. Please do the same.

index.asp

Code: Select all

<html>
<head>
<title>Check ASP</title>
</head>
<body link=#0000FF alink=#0000FF vlink=#0000FF text=#000000 bgcolor=#ffffff>
<font face=tahoma size=3>
<%
If Session("mysite") <> "me" Then
%>
Not Me, [url=login.asp]Change[/url]
<%
Else
%>
Me, [url=logout.asp]Change[/url]
<%
End If
%>
</font>
</body>
</html>
login.asp

Code: Select all

<%
Session("mysite") = "me"
Response.Redirect "index.asp"
%>
logout.asp

Code: Select all

<%
Session.Abandon
Response.Redirect "index.asp"
%>
Edited by moderator. For code use code tags !!
Image
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

index.php

Code: Select all

<?$mysite=$_SESSION["mysite"];?>
<html>
<head>
<title>Check ASP</title>
</head>
<body link=#0000FF alink=#0000FF vlink=#0000FF text=#000000 bgcolor=#ffffff>
<font face=tahoma size=3>

<? 
If ($mysite != "me" )
	echo "[url=login.asp]Change[/url]";
else
	echo "[url=logout.asp]Change[/url]";
?>

</font>
</body>
</html>
login.php

Code: Select all

<?
	session_start();
	$_SESSION["mysite"] = "me";

// header must be before any output, it would be best if u use separate file for sesion registration, like here- only session registration and redirection
	Header(location:index.php);
?>
logout.php

Code: Select all

<?
	session_destroy();
	header("location: index.php");
?>
Try this, it should be ok. If somthing will not work, paste here and error
Image
Praveen
Posts: 146
Joined: Fri Oct 21, 2005 11:47 am
Contact:

Post by Praveen »

The same code, with this result in index.php.

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in c:\Inetpub\www\phplogin\index.php on line 11
Image
Praveen
Posts: 146
Joined: Fri Oct 21, 2005 11:47 am
Contact:

Post by Praveen »

I changed the code of index.php to

Code: Select all

<?$mysite=$_SESSION["mysite"];?> 
<html> 
<head> 
<title>Check ASP</title> 
</head> 
<body link=#0000FF alink=#0000FF vlink=#0000FF text=#000000 bgcolor=#ffffff> 
<font face=tahoma size=3> 

<? 
If ($mysite != "me" ) 
   echo "[url=login.php]Login[/url]"; 
else 
   echo "[url=logout.php]Logout[/url]"; 
?> 

</font> 
</body> 
</html>
Then the error was:

Parse error: parse error, unexpected ':' in c:\Inetpub\www\phplogin\login.php on line 6
Image
Post Reply