Page 1 of 1
[SOLVED] needs help with saving a $variable to a file &
Posted: Thu Nov 25, 2004 10:42 am
by asi0917
i am totaly new to server side scripting and found this niffty script
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip;
?>
can someone tell me how to save $ip to a file?
also i was wondering what all this file.php?code=code stuff is about
also, i was on greycobra.com and keep encountering the problem of this information i need, for example
http://www.greycobra.com/tutorials.php? ... view&id=53
asks you for your host, database and i don't even know where mySQL surver thingy is or what it is exactly
and
FYI i use
http://hosting.mixcat.com/ so.. ya
_________________________________
help=goodness
Posted: Thu Nov 25, 2004 7:21 pm
by AVATAr
1. how to write something to a file [php_man]fwrite[/php_man]
2. file.php?variable=code
you can fetch the code in the url with the reserved variable $_GET, in this case you just use $_GET['variable'] to use code.
Re: [SOLVED] needs help with saving a $variable to a file &a
Posted: Thu Nov 25, 2004 8:06 pm
by josh
asi0917 wrote:
also i was wondering what all this file.php?code=code stuff is about
That is how you pass a variable to a script
create test.php and put the following code in it:
then go to test.php?code=code
This is how php gets user input, to get a specific input do something like:
Code: Select all
<?php
echo ("I like " . $_REQUEST['affection']);
?>
then call test.php?affection=php
This should print out "I like php"
see where I'm going?
asi0917 wrote:
asks you for your host, database and i don't even know where mySQL surver thingy is or what it is exactly
and
FYI i use
http://hosting.mixcat.com/ so.. ya
That is an issue to take up with hosting.mixcat.com
Is your email and ftp and host logins/passwords all the same? If so then your mysql password is probably the same as well, usually the host is "localhost"
Code: Select all
<?php
$link = mysql_connect('localhost', username', 'password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
?>
Use this script to test the passwords, if you get "connected succesfully" then you have the right info
What this is doing is connecting up to an sql server, sql means simple query language and a sql server basically allows you to interact with a database from your script.
Posted: Sat Nov 27, 2004 12:39 am
by asi0917
thank you
Posted: Sat Nov 27, 2004 12:49 am
by asi0917
so why doesn't this work?
Code: Select all
<html>
<body>
<a href="http://hosting.mixcat.com/asi0917/welcome.php?=1">
#1</a>
<br>
<a href="http://hosting.mixcat.com/asi0917/welcome.php?=2">
#2</a>
<br>
<?php
echo ("I like " . $_REQUEST['link']);
?>
<?
if ($_REQUEST['link'])===1);
{
echo "you clicked link #1";
}
else
{
echo "you clicked link #2";
}
?>
</body>
</html>
????
?>
Posted: Sat Nov 27, 2004 1:26 am
by rehfeld
2 reasons
1, you didnt name the variable in the url
you did
?=1
you should have done
?link=1
2,
you are improperly using the === operator.
=== means equal AND of the same data type
== just means equal, and is less specific
data which comes trhough $_REQUEST is generally of data type string
you are saying
if $_REQUEST['link'] is equal to and the same type, as integer 1
you want to say:
if $_REQUEST['link'] is equal to and the same type, as string 1
this would work
Code: Select all
if ($_REQUEST['link']) === '1') { // the quotes mean its a string
Posted: Sat Nov 27, 2004 12:27 pm
by asi0917
awwwwww i wasn't sure waht the difference was between === and == but that was a typo

thanks for the correction