Php?

Status
Not open for further replies.

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Im having issues with php.
How do you detect IP address with PHP?
How do you make a cookie if the page is writen using PHP?
Can a variable writen in one script be used in another?
If anyone can help me that would be a great help.
If you are going to redirect me to the tutorials please give me an exact link because may people have me going crazy searching. Thank You People!:biggrin:
 

shaunak

New Member
Messages
320
Reaction score
0
Points
0
Q 2>
Cookies tut here:


Q 1>
IP display CODE:
Code:
<?PHP

$ipaddress = $REMOTE_ADDR;

Echo "Your IP is $ipaddress!";

?>

PS: you can visit dynamicdrive.com for some great sniplets
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
shanuak: that wouldn't work on x10 cause global variables are turned off.
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
Im having issues with php.
How do you detect IP address with PHP?
How do you make a cookie if the page is writen using PHP?
Can a variable writen in one script be used in another?
If anyone can help me that would be a great help.
If you are going to redirect me to the tutorials please give me an exact link because may people have me going crazy searching. Thank You People!:biggrin:

1 - $_SERVER['REMOTE_ADDR']
(I believe $_ENV['REMOTE_ADDR'] will work, like slothie said, since $_ENV contains $_SERVER basically)

2 - setcookie() to set cookies and and $_COOKIE to access them. If you need to set cookies you need to do it before sending output to the browser. If you get an error because of headers already being sent, that is why. (There are alternatives, such as output buffering)

3 -
- Variables only can be used within the same script that is running. If you create a variable in a script and then include another script into the current one, that variable will be available within the included script.
- You can pass information and data between page/script loads using things like sessions, databases, HTTP GET and POST, and cookies.
- Also, variables have scope, which is 'the context within which it was defined.' That means if you define a variable in a function, that variable is only available within that function. If you create a variable outside of a function, it is not available in a function. You can use the keyword 'global' to move a variable into the global scope (accessible everywhere) if needed. (Does that make sense to you?)
For more information - http://us.php.net/global
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Or you could use the $_SESSION to pass variables from 1 script to another.
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Thanks for the help but I find myself stuck again and if anyone could help It would be a great help:biggrin:

for this source code:
<?php
$Webpage="<p>Poo</p>";
setcookie("Attempts", "1", time()+7200);
echo $Webpage;
?>

How do you set a cookie if the web page is written by PHP?
How to make an email not turn up under spam?
How do you Encrypt a form using PHP?
How do you redirect a user with PHP before the page loads?
Where does it say in w3schools or PHP.net how to get IP address?

All these things I have not found in w3schools or PHP.net
Thank you for helping!!!!!!!!!!!!!!!!!:biggrin:
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Seems okay to me for that source.

How do you set a cookie if the web page is written by PHP?
I thought that's already been explained. SetCookie. To retreive its contents, you would use
PHP:
echo $_COOKIE['Attempts'];


How to make an email not turn up under spam?

Set your mail headers and everything completely otherwise you'll have to go through your mail provider. The easiest way is to use google's SMTP

How do you Encrypt a form using PHP?
I Don't quite get this.

How do you redirect a user with PHP before the page loads?
Use
PHP:
header("Location: http://google.com");


Where does it say in w3schools or PHP.net how to get IP address?

Refer to http://au3.php.net/manual/en/reserved.variables.php#reserved.variables.environment
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
The cookie source gives me a warning about seting the cookie that you have to set it before any output. I added to you rep
 
Last edited:

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Make sure you do not have any blank spaces before your <?php or whatever. From your code, you only echo AFTER you set the cookie, which is why I say it looks fine to me.

Oh, thanks for the rep :p
 
Last edited:

Chris Z

Active Member
Messages
5,603
Reaction score
0
Points
36
And if you can't/don't want to do what Slothie suggested try:
PHP:
<?php
ob_start();
echo 'other shiz here';
//Some more shiz!
//blah
//blah
setcookie();
?>
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
I don't really recommend the use of ob_start() unless absolutely necessary. This makes debugging hell.
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Now I am confussed. When you (set_cookie), does this echo the header there and then? Would echoing after this then close the header and open the body?
Must you not define a header first?
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
What header? Cookies and sessions must be opened before ANYTHING is output the browser, including the
PHP:
header():
command.
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Ok, feeling even more doff !

How would you write a script that places a cookie ('key=>value'), retrieves it and then prints the 'value' to a page? The page must have a expired header.
 
Status
Not open for further replies.
Top